From c21a117677f7f6b036aff40928f0e4be117b4485 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:17:36 +0100 Subject: [PATCH] add rudimentary test for process_creation_flags arg --- src/tufup/utils/platform_specific.py | 2 ++ tests/test_utils_platform_specific.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/tufup/utils/platform_specific.py b/src/tufup/utils/platform_specific.py index a40043c..096519c 100644 --- a/src/tufup/utils/platform_specific.py +++ b/src/tufup/utils/platform_specific.py @@ -218,6 +218,8 @@ def _install_update_win( # using the process_creation_flags argument if process_creation_flags is None: process_creation_flags = subprocess.CREATE_NEW_CONSOLE + else: + logger.debug('using custom process creation flags') # we use Popen() instead of run(), because the latter blocks execution subprocess.Popen([script_path], creationflags=process_creation_flags) logger.debug('exiting') diff --git a/tests/test_utils_platform_specific.py b/tests/test_utils_platform_specific.py index 1b70216..cbfa04e 100644 --- a/tests/test_utils_platform_specific.py +++ b/tests/test_utils_platform_specific.py @@ -22,6 +22,7 @@ ) DUMMY_APP_CONTENT = f""" +import subprocess import sys sys.path.append('{(BASE_DIR.parent / 'src').as_posix()}') from tufup.utils.platform_specific import install_update @@ -176,6 +177,22 @@ def test_install_update_log_file(self): log_file_content = log_file_path.read_text() self.assertTrue(log_file_content) + @unittest.skipIf( + condition=not ON_WINDOWS, reason='process_creation_flags is for windows only' + ) + def test_install_update_process_creation_flags(self): + # the log file is only used to verify that the batch file has run successfully + log_file_name = 'install.log' + extra_kwargs_strings = [ + 'process_creation_flags=subprocess.CREATE_NO_WINDOW', + f'log_file_name="{log_file_name}"', + ] + # run the dummy app in a separate process + self.run_dummy_app(extra_kwargs_strings=extra_kwargs_strings) + # a log file should exist + log_file_path = self.dst_dir / log_file_name + self.assertTrue(log_file_path.read_text()) + @unittest.skipIf( condition=not ON_WINDOWS, reason='windows batch files are windows only' )