Skip to content

Commit af1db4e

Browse files
authored
bpo-45582: Fix getpath_isxfile() and test_embed on Windows (GH-29930)
1 parent 612e59b commit af1db4e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/test/test_embed.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def _get_expected_config(self):
575575
return configs
576576

577577
def get_expected_config(self, expected_preconfig, expected,
578-
env, api, modify_path_cb=None):
578+
env, api, modify_path_cb=None, cwd=None):
579579
configs = self._get_expected_config()
580580

581581
pre_config = configs['pre_config']
@@ -618,6 +618,14 @@ def get_expected_config(self, expected_preconfig, expected,
618618
expected['base_executable'] = default_executable
619619
if expected['program_name'] is self.GET_DEFAULT_CONFIG:
620620
expected['program_name'] = './_testembed'
621+
if MS_WINDOWS:
622+
# follow the calculation in getpath.py
623+
tmpname = expected['program_name'] + '.exe'
624+
if cwd:
625+
tmpname = os.path.join(cwd, tmpname)
626+
if os.path.isfile(tmpname):
627+
expected['program_name'] += '.exe'
628+
del tmpname
621629

622630
config = configs['config']
623631
for key, value in expected.items():
@@ -711,7 +719,7 @@ def check_all_configs(self, testname, expected_config=None,
711719
self.get_expected_config(expected_preconfig,
712720
expected_config,
713721
env,
714-
api, modify_path_cb)
722+
api, modify_path_cb, cwd)
715723

716724
out, err = self.run_embedded_interpreter(testname,
717725
env=env, cwd=cwd)

Modules/getpath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
230230
DWORD attr = GetFileAttributesW(path);
231231
r = (attr != INVALID_FILE_ATTRIBUTES) &&
232232
!(attr & FILE_ATTRIBUTE_DIRECTORY) &&
233-
SUCCEEDED(PathCchFindExtension(path, cchPath, &ext)) &&
233+
SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) &&
234234
(CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
235235
? Py_True : Py_False;
236236
#else

0 commit comments

Comments
 (0)