gh-99442: Fix handling in py.exe launcher when argv[0] does not include a file extension (GH-99542)

This commit is contained in:
Steve Dower 2022-11-18 14:14:56 +00:00 committed by GitHub
parent 4f5e1cb00a
commit a220c6d1ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 51 deletions

View file

@ -173,7 +173,7 @@ class RunPyMixin:
errors="ignore",
) as p:
p.stdin.close()
version = next(p.stdout).splitlines()[0].rpartition(" ")[2]
version = next(p.stdout, "\n").splitlines()[0].rpartition(" ")[2]
p.stdout.read()
p.wait(10)
if not sys.version.startswith(version):
@ -467,6 +467,15 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
self.assertEqual("X.Y-arm64.exe -X fake_arg_for_test -arg", data["stdout"].strip())
def test_py_default_short_argv0(self):
with self.py_ini(TEST_PY_COMMANDS):
for argv0 in ['"py.exe"', 'py.exe', '"py"', 'py']:
with self.subTest(argv0):
data = self.run_py(["--version"], argv=f'{argv0} --version')
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100", data["SearchInfo.tag"])
self.assertEqual(f'X.Y.exe --version', data["stdout"].strip())
def test_py_default_in_list(self):
data = self.run_py(["-0"], env=TEST_PY_ENV)
default = None