From 7aa9dc17503f6e45479612c15f7eb15dd6c3dad9 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 16 Jun 2022 16:01:56 +0900 Subject: [PATCH 1/5] gh-89745: Avoid exact match when comparing program_name in test_embed on Windows --- Lib/test/test_embed.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index f1ca6da147376c..7b9fd1f1568383 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -629,7 +629,7 @@ def _get_expected_config(self): return configs def get_expected_config(self, expected_preconfig, expected, - env, api, modify_path_cb=None, cwd=None): + env, api, modify_path_cb=None): configs = self._get_expected_config() pre_config = configs['pre_config'] @@ -672,14 +672,6 @@ def get_expected_config(self, expected_preconfig, expected, expected['base_executable'] = default_executable if expected['program_name'] is self.GET_DEFAULT_CONFIG: expected['program_name'] = './_testembed' - if MS_WINDOWS: - # follow the calculation in getpath.py - tmpname = expected['program_name'] + '.exe' - if cwd: - tmpname = os.path.join(cwd, tmpname) - if os.path.isfile(tmpname): - expected['program_name'] += '.exe' - del tmpname config = configs['config'] for key, value in expected.items(): @@ -709,6 +701,9 @@ def check_pre_config(self, configs, expected): def check_config(self, configs, expected): config = dict(configs['config']) + if MS_WINDOWS and (value := config.get('program_name')): + ptn = '_d.exe$' if debug_build(sys.executable) else '.exe$' + config['program_name'] = re.sub(ptn, '', value, 1, re.I) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: config.pop(key, None) @@ -773,7 +768,7 @@ def check_all_configs(self, testname, expected_config=None, self.get_expected_config(expected_preconfig, expected_config, env, - api, modify_path_cb, cwd) + api, modify_path_cb) out, err = self.run_embedded_interpreter(testname, env=env, cwd=cwd) From ce853e4ba9b3b5d82d43b7937a64f931a56a742f Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:52:18 +0900 Subject: [PATCH 2/5] raw string --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 7b9fd1f1568383..92156d8cfb3689 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -702,7 +702,7 @@ def check_pre_config(self, configs, expected): def check_config(self, configs, expected): config = dict(configs['config']) if MS_WINDOWS and (value := config.get('program_name')): - ptn = '_d.exe$' if debug_build(sys.executable) else '.exe$' + ptn = r'_d\.exe$' if debug_build(sys.executable) else r'\.exe$' config['program_name'] = re.sub(ptn, '', value, 1, re.I) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: From 4bd62a40fb66f57997a2f1f0b2fc0ef643e20244 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 16 Jun 2022 22:30:21 +0900 Subject: [PATCH 3/5] str check --- Lib/test/test_embed.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 92156d8cfb3689..5f8fb3ebd91413 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -701,9 +701,11 @@ def check_pre_config(self, configs, expected): def check_config(self, configs, expected): config = dict(configs['config']) - if MS_WINDOWS and (value := config.get('program_name')): - ptn = r'_d\.exe$' if debug_build(sys.executable) else r'\.exe$' - config['program_name'] = re.sub(ptn, '', value, 1, re.I) + if MS_WINDOWS: + value = config.get('program_name') + if value and isinstance(value, str): + ptn = '_d.exe$' if debug_build(sys.executable) else '.exe$' + config['program_name'] = re.sub(ptn, '', value, 1, re.IGNORECASE) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: config.pop(key, None) From caaec5496c513e34129ab08987b525a09b8568a2 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 16 Jun 2022 23:00:21 +0900 Subject: [PATCH 4/5] fix missing ce853e4 --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 5f8fb3ebd91413..52c70e88234b17 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -704,7 +704,7 @@ def check_config(self, configs, expected): if MS_WINDOWS: value = config.get('program_name') if value and isinstance(value, str): - ptn = '_d.exe$' if debug_build(sys.executable) else '.exe$' + ptn = r'_d\.exe$' if debug_build(sys.executable) else r'\.exe$' config['program_name'] = re.sub(ptn, '', value, 1, re.IGNORECASE) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: From 383a32740810c9619da9ef925ee6901519ed32ea Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Fri, 17 Jun 2022 01:53:16 +0900 Subject: [PATCH 5/5] no regex --- Lib/test/test_embed.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 52c70e88234b17..0bc1804673f71a 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -702,10 +702,10 @@ def check_pre_config(self, configs, expected): def check_config(self, configs, expected): config = dict(configs['config']) if MS_WINDOWS: - value = config.get('program_name') + value = config.get(key := 'program_name') if value and isinstance(value, str): - ptn = r'_d\.exe$' if debug_build(sys.executable) else r'\.exe$' - config['program_name'] = re.sub(ptn, '', value, 1, re.IGNORECASE) + ext = '_d.exe' if debug_build(sys.executable) else '.exe' + config[key] = value[:len(value.lower().removesuffix(ext))] for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: config.pop(key, None)