From b7650f38331816761b3a25c4b7a2cd4677eb8acb Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 6 Dec 2021 09:48:29 +0900 Subject: [PATCH 1/2] Fix the failure of getpath_isxfile() --- Modules/getpath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/getpath.c b/Modules/getpath.c index f77b18eee95b65..acb945c25b0864 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -230,7 +230,7 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && - SUCCEEDED(PathCchFindExtension(path, cchPath, &ext)) && + SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && (CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) ? Py_True : Py_False; #else From d6ad25ae154d18283883ba6861b8f7a2cc2ab1ae Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 6 Dec 2021 09:49:40 +0900 Subject: [PATCH 2/2] Expect the calculated program_name following getpath.py --- Lib/test/test_embed.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 3620a7619601df..94161b651ff86c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -575,7 +575,7 @@ def _get_expected_config(self): return configs def get_expected_config(self, expected_preconfig, expected, - env, api, modify_path_cb=None): + env, api, modify_path_cb=None, cwd=None): configs = self._get_expected_config() pre_config = configs['pre_config'] @@ -618,6 +618,14 @@ 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(): @@ -711,7 +719,7 @@ def check_all_configs(self, testname, expected_config=None, self.get_expected_config(expected_preconfig, expected_config, env, - api, modify_path_cb) + api, modify_path_cb, cwd) out, err = self.run_embedded_interpreter(testname, env=env, cwd=cwd)