Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3d5715

Browse files
authored
bpo-46566: Make test_launcher more robust to a variety of installs (GH-32204)
1 parent 2ab609d commit f3d5715

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

Lib/test/test_launcher.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ def find_py(cls):
151151
py_exe = Path(p) / PY_EXE
152152
if py_exe.is_file():
153153
break
154+
else:
155+
py_exe = None
156+
157+
# Test launch and check version, to exclude installs of older
158+
# releases when running outside of a source tree
159+
if py_exe:
160+
try:
161+
with subprocess.Popen(
162+
[py_exe, "-h"],
163+
stdin=subprocess.PIPE,
164+
stdout=subprocess.PIPE,
165+
stderr=subprocess.PIPE,
166+
encoding="ascii",
167+
errors="ignore",
168+
) as p:
169+
p.stdin.close()
170+
version = next(p.stdout).splitlines()[0].rpartition(" ")[2]
171+
p.stdout.read()
172+
p.wait(10)
173+
if not sys.version.startswith(version):
174+
py_exe = None
175+
except OSError:
176+
py_exe = None
177+
154178
if not py_exe:
155179
raise unittest.SkipTest(
156180
"cannot locate '{}' for test".format(PY_EXE)
@@ -162,6 +186,7 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
162186
self.py_exe = self.find_py()
163187

164188
env = {**os.environ, **(env or {}), "PYLAUNCHER_DEBUG": "1", "PYLAUNCHER_DRYRUN": "1"}
189+
env.pop("VIRTUAL_ENV", None)
165190
with subprocess.Popen(
166191
[self.py_exe, *args],
167192
env=env,
@@ -216,7 +241,7 @@ def setUpClass(cls):
216241

217242
if support.verbose:
218243
p = subprocess.check_output("reg query HKCU\\Software\\Python /s")
219-
print(p.decode('mbcs'))
244+
#print(p.decode('mbcs'))
220245

221246

222247
@classmethod
@@ -251,9 +276,9 @@ def test_list(self):
251276
found = {}
252277
expect = {}
253278
for line in data["stdout"].splitlines():
254-
m = re.match(r"\s*(.+?)\s+(.+)$", line)
279+
m = re.match(r"\s*(.+?)\s+?(\*\s+)?(.+)$", line)
255280
if m:
256-
found[m.group(1)] = m.group(2)
281+
found[m.group(1)] = m.group(3)
257282
for company in TEST_DATA:
258283
company_data = TEST_DATA[company]
259284
tags = [t for t in company_data if isinstance(company_data[t], dict)]
@@ -276,9 +301,9 @@ def test_list_paths(self):
276301
found = {}
277302
expect = {}
278303
for line in data["stdout"].splitlines():
279-
m = re.match(r"\s*(.+?)\s+(.+)$", line)
304+
m = re.match(r"\s*(.+?)\s+?(\*\s+)?(.+)$", line)
280305
if m:
281-
found[m.group(1)] = m.group(2)
306+
found[m.group(1)] = m.group(3)
282307
for company in TEST_DATA:
283308
company_data = TEST_DATA[company]
284309
tags = [t for t in company_data if isinstance(company_data[t], dict)]
@@ -415,9 +440,10 @@ def test_install(self):
415440
# If winget is runnable, we should find it. Otherwise, we'll be trying
416441
# to open the Store.
417442
try:
418-
subprocess.check_call(["winget.exe", "--version"])
443+
subprocess.check_call(["winget.exe", "--version"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
419444
except FileNotFoundError:
420445
self.assertIn("ms-windows-store://", cmd)
421446
else:
422447
self.assertIn("winget.exe", cmd)
448+
# Both command lines include the store ID
423449
self.assertIn("9PJPW5LDXLZ5", cmd)

0 commit comments

Comments
 (0)