mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
gh-114272: Fix or skip tests that fail due to spaces in paths (GH-114451)
This commit is contained in:
parent
d5c21c12c1
commit
c63c6142f9
4 changed files with 45 additions and 25 deletions
|
@ -207,7 +207,7 @@ class SubprocessMixin:
|
||||||
|
|
||||||
def test_kill_issue43884(self):
|
def test_kill_issue43884(self):
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
blocking_shell_command = f'{sys.executable} -c "import time; time.sleep(2)"'
|
blocking_shell_command = f'"{sys.executable}" -c "import time; time.sleep(2)"'
|
||||||
else:
|
else:
|
||||||
blocking_shell_command = 'sleep 1; sleep 1'
|
blocking_shell_command = 'sleep 1; sleep 1'
|
||||||
creationflags = 0
|
creationflags = 0
|
||||||
|
@ -745,7 +745,10 @@ class SubprocessMixin:
|
||||||
|
|
||||||
def test_create_subprocess_env_shell(self) -> None:
|
def test_create_subprocess_env_shell(self) -> None:
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
cmd = f'''{sys.executable} -c "import os, sys; sys.stdout.write(os.getenv('FOO'))"'''
|
executable = sys.executable
|
||||||
|
if sys.platform == "win32":
|
||||||
|
executable = f'"{executable}"'
|
||||||
|
cmd = f'''{executable} -c "import os, sys; sys.stdout.write(os.getenv('FOO'))"'''
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["FOO"] = "bar"
|
env["FOO"] = "bar"
|
||||||
proc = await asyncio.create_subprocess_shell(
|
proc = await asyncio.create_subprocess_shell(
|
||||||
|
|
|
@ -90,6 +90,12 @@ TEST_PY_COMMANDS = "\n".join([
|
||||||
"test-command=TEST_EXE.exe",
|
"test-command=TEST_EXE.exe",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def quote(s):
|
||||||
|
s = str(s)
|
||||||
|
return f'"{s}"' if " " in s else s
|
||||||
|
|
||||||
|
|
||||||
def create_registry_data(root, data):
|
def create_registry_data(root, data):
|
||||||
def _create_registry_data(root, key, value):
|
def _create_registry_data(root, key, value):
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
|
@ -542,10 +548,10 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data1 = self.run_py([], env={**env, "PY_PYTHON": "PythonTestSuite/3"})
|
data1 = self.run_py([], env={**env, "PY_PYTHON": "PythonTestSuite/3"})
|
||||||
data2 = self.run_py(["-V:PythonTestSuite/3"], env={**env, "PY_PYTHON": "PythonTestSuite/3"})
|
data2 = self.run_py(["-V:PythonTestSuite/3"], env={**env, "PY_PYTHON": "PythonTestSuite/3"})
|
||||||
# Compare stdout, because stderr goes via ascii
|
# Compare stdout, because stderr goes via ascii
|
||||||
self.assertEqual(data1["stdout"].strip(), str(venv_exe))
|
self.assertEqual(data1["stdout"].strip(), quote(venv_exe))
|
||||||
self.assertEqual(data1["SearchInfo.lowPriorityTag"], "True")
|
self.assertEqual(data1["SearchInfo.lowPriorityTag"], "True")
|
||||||
# Ensure passing the argument doesn't trigger the same behaviour
|
# Ensure passing the argument doesn't trigger the same behaviour
|
||||||
self.assertNotEqual(data2["stdout"].strip(), str(venv_exe))
|
self.assertNotEqual(data2["stdout"].strip(), quote(venv_exe))
|
||||||
self.assertNotEqual(data2["SearchInfo.lowPriorityTag"], "True")
|
self.assertNotEqual(data2["SearchInfo.lowPriorityTag"], "True")
|
||||||
|
|
||||||
def test_py_shebang(self):
|
def test_py_shebang(self):
|
||||||
|
@ -554,7 +560,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100", data["SearchInfo.tag"])
|
self.assertEqual("3.100", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y.exe -prearg {quote(script)} -postarg", data["stdout"].strip())
|
||||||
|
|
||||||
def test_python_shebang(self):
|
def test_python_shebang(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -562,7 +568,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100", data["SearchInfo.tag"])
|
self.assertEqual("3.100", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y.exe -prearg {quote(script)} -postarg", data["stdout"].strip())
|
||||||
|
|
||||||
def test_py2_shebang(self):
|
def test_py2_shebang(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -570,7 +576,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100-32", data["SearchInfo.tag"])
|
self.assertEqual("3.100-32", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y-32.exe -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_py3_shebang(self):
|
def test_py3_shebang(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -578,7 +585,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
|
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_py_shebang_nl(self):
|
def test_py_shebang_nl(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -586,7 +594,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100", data["SearchInfo.tag"])
|
self.assertEqual("3.100", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y.exe -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_py2_shebang_nl(self):
|
def test_py2_shebang_nl(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -594,7 +603,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100-32", data["SearchInfo.tag"])
|
self.assertEqual("3.100-32", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y-32.exe -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_py3_shebang_nl(self):
|
def test_py3_shebang_nl(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -602,7 +612,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script, "-postarg"])
|
data = self.run_py([script, "-postarg"])
|
||||||
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
|
||||||
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
|
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
|
||||||
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_py_shebang_short_argv0(self):
|
def test_py_shebang_short_argv0(self):
|
||||||
with self.py_ini(TEST_PY_DEFAULTS):
|
with self.py_ini(TEST_PY_DEFAULTS):
|
||||||
|
@ -630,7 +641,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
[script, "-postarg"],
|
[script, "-postarg"],
|
||||||
env={"PATH": f"{exe.parent};{os.getenv('PATH')}"},
|
env={"PATH": f"{exe.parent};{os.getenv('PATH')}"},
|
||||||
)
|
)
|
||||||
self.assertEqual(f"{exe} -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"{quote(exe)} -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_search_path_exe(self):
|
def test_search_path_exe(self):
|
||||||
# Leave the .exe on the name to ensure we don't add it a second time
|
# Leave the .exe on the name to ensure we don't add it a second time
|
||||||
|
@ -643,7 +655,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
[script, "-postarg"],
|
[script, "-postarg"],
|
||||||
env={"PATH": f"{exe.parent};{os.getenv('PATH')}"},
|
env={"PATH": f"{exe.parent};{os.getenv('PATH')}"},
|
||||||
)
|
)
|
||||||
self.assertEqual(f"{exe} -prearg {script} -postarg", data["stdout"].strip())
|
self.assertEqual(f"{quote(exe)} -prearg {quote(script)} -postarg",
|
||||||
|
data["stdout"].strip())
|
||||||
|
|
||||||
def test_recursive_search_path(self):
|
def test_recursive_search_path(self):
|
||||||
stem = self.get_py_exe().stem
|
stem = self.get_py_exe().stem
|
||||||
|
@ -654,7 +667,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
env={"PATH": f"{self.get_py_exe().parent};{os.getenv('PATH')}"},
|
env={"PATH": f"{self.get_py_exe().parent};{os.getenv('PATH')}"},
|
||||||
)
|
)
|
||||||
# The recursive search is ignored and we get normal "py" behavior
|
# The recursive search is ignored and we get normal "py" behavior
|
||||||
self.assertEqual(f"X.Y.exe {script}", data["stdout"].strip())
|
self.assertEqual(f"X.Y.exe {quote(script)}", data["stdout"].strip())
|
||||||
|
|
||||||
def test_install(self):
|
def test_install(self):
|
||||||
data = self.run_py(["-V:3.10"], env={"PYLAUNCHER_ALWAYS_INSTALL": "1"}, expect_returncode=111)
|
data = self.run_py(["-V:3.10"], env={"PYLAUNCHER_ALWAYS_INSTALL": "1"}, expect_returncode=111)
|
||||||
|
@ -674,7 +687,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
with self.script("#! C:/some_random_app -witharg") as script:
|
with self.script("#! C:/some_random_app -witharg") as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f"C:\\some_random_app -witharg {script}",
|
f"C:\\some_random_app -witharg {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -682,7 +695,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
with self.script("#! ..\\some_random_app -witharg") as script:
|
with self.script("#! ..\\some_random_app -witharg") as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f"{script.parent.parent}\\some_random_app -witharg {script}",
|
f"{quote(script.parent.parent / 'some_random_app')} -witharg {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -690,14 +703,14 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
with self.script('#! "some random app" -witharg') as script:
|
with self.script('#! "some random app" -witharg') as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f'"{script.parent}\\some random app" -witharg {script}',
|
f"{quote(script.parent / 'some random app')} -witharg {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.script('#! some" random "app -witharg') as script:
|
with self.script('#! some" random "app -witharg') as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f'"{script.parent}\\some random app" -witharg {script}',
|
f"{quote(script.parent / 'some random app')} -witharg {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -705,7 +718,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
with self.script('#! some\\" random "app -witharg') as script:
|
with self.script('#! some\\" random "app -witharg') as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f'"{script.parent}\\some\\ random app" -witharg {script}',
|
f"{quote(script.parent / 'some/ random app')} -witharg {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -714,7 +727,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
with self.script('#! test-command arg1') as script:
|
with self.script('#! test-command arg1') as script:
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f"TEST_EXE.exe arg1 {script}",
|
f"TEST_EXE.exe arg1 {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -723,7 +736,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
data = self.run_py([script])
|
data = self.run_py([script])
|
||||||
expect = script.parent / "/usr/bin/not-python"
|
expect = script.parent / "/usr/bin/not-python"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
f"{expect} arg1 {script}",
|
f"{quote(expect)} arg1 {quote(script)}",
|
||||||
data["stdout"].strip(),
|
data["stdout"].strip(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -746,8 +759,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
||||||
|
|
||||||
with self.script(f'#! /usr/bin/env {stem} arg1') as script:
|
with self.script(f'#! /usr/bin/env {stem} arg1') as script:
|
||||||
data = self.run_py([script], env=env)
|
data = self.run_py([script], env=env)
|
||||||
self.assertEqual(data["stdout"].strip(), f"{venv_exe} arg1 {script}")
|
self.assertEqual(data["stdout"].strip(), f"{quote(venv_exe)} arg1 {quote(script)}")
|
||||||
|
|
||||||
with self.script(f'#! /usr/bin/env {exe.stem} arg1') as script:
|
with self.script(f'#! /usr/bin/env {exe.stem} arg1') as script:
|
||||||
data = self.run_py([script], env=env)
|
data = self.run_py([script], env=env)
|
||||||
self.assertEqual(data["stdout"].strip(), f"{exe} arg1 {script}")
|
self.assertEqual(data["stdout"].strip(), f"{quote(exe)} arg1 {quote(script)}")
|
||||||
|
|
|
@ -4596,8 +4596,11 @@ class FDInheritanceTests(unittest.TestCase):
|
||||||
with open(filename, "w") as fp:
|
with open(filename, "w") as fp:
|
||||||
print(code, file=fp, end="")
|
print(code, file=fp, end="")
|
||||||
|
|
||||||
cmd = [sys.executable, filename]
|
executable = sys.executable
|
||||||
exitcode = os.spawnl(os.P_WAIT, cmd[0], *cmd)
|
cmd = [executable, filename]
|
||||||
|
if os.name == "nt" and " " in cmd[0]:
|
||||||
|
cmd[0] = f'"{cmd[0]}"'
|
||||||
|
exitcode = os.spawnl(os.P_WAIT, executable, *cmd)
|
||||||
self.assertEqual(exitcode, 0)
|
self.assertEqual(exitcode, 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,7 @@ class ImportTest(unittest.TestCase):
|
||||||
webbrowser.get('fakebrowser')
|
webbrowser.get('fakebrowser')
|
||||||
self.assertIsNotNone(webbrowser._tryorder)
|
self.assertIsNotNone(webbrowser._tryorder)
|
||||||
|
|
||||||
|
@unittest.skipIf(" " in sys.executable, "test assumes no space in path (GH-114452)")
|
||||||
def test_synthesize(self):
|
def test_synthesize(self):
|
||||||
webbrowser = import_helper.import_fresh_module('webbrowser')
|
webbrowser = import_helper.import_fresh_module('webbrowser')
|
||||||
name = os.path.basename(sys.executable).lower()
|
name = os.path.basename(sys.executable).lower()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue