summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_launcher.py57
1 files changed, 40 insertions, 17 deletions
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py
index 47152d4..351a638 100644
--- a/Lib/test/test_launcher.py
+++ b/Lib/test/test_launcher.py
@@ -67,12 +67,17 @@ TEST_PY_ENV = dict(
)
-TEST_PY_COMMANDS = "\n".join([
+TEST_PY_DEFAULTS = "\n".join([
"[defaults]",
- *[f"{k[3:].lower()}={v}" for k, v in TEST_PY_ENV.items()]
+ *[f"{k[3:].lower()}={v}" for k, v in TEST_PY_ENV.items()],
])
+TEST_PY_COMMANDS = "\n".join([
+ "[commands]",
+ "test-command=TEST_EXE.exe",
+])
+
def create_registry_data(root, data):
def _create_registry_data(root, key, value):
if isinstance(value, dict):
@@ -429,21 +434,21 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertTrue(data["env.tag"].startswith("2."), data["env.tag"])
def test_py_default(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
data = self.run_py(["-arg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100", data["SearchInfo.tag"])
self.assertEqual("X.Y.exe -arg", data["stdout"].strip())
def test_py2_default(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
data = self.run_py(["-2", "-arg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100-32", data["SearchInfo.tag"])
self.assertEqual("X.Y-32.exe -arg", data["stdout"].strip())
def test_py3_default(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
data = self.run_py(["-3", "-arg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
@@ -468,7 +473,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
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):
+ with self.py_ini(TEST_PY_DEFAULTS):
for argv0 in ['"py.exe"', 'py.exe', '"py"', 'py']:
with self.subTest(argv0):
data = self.run_py(["--version"], argv=f'{argv0} --version')
@@ -518,7 +523,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertNotEqual(data2["SearchInfo.lowPriorityTag"], "True")
def test_py_shebang(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python -prearg") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -526,7 +531,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
def test_python_shebang(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! python -prearg") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -534,7 +539,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
def test_py2_shebang(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python2 -prearg") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -542,7 +547,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())
def test_py3_shebang(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python3 -prearg") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -550,7 +555,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
def test_py_shebang_nl(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -558,7 +563,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
def test_py2_shebang_nl(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python2 -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -566,7 +571,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())
def test_py3_shebang_nl(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python3 -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
@@ -574,7 +579,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
def test_py_shebang_short_argv0(self):
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script("#! /usr/bin/python -prearg") as script:
# Override argv to only pass "py.exe" as the command
data = self.run_py([script, "-postarg"], argv=f'"py.exe" "{script}" -postarg')
@@ -591,7 +596,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
def test_search_path(self):
stem = Path(sys.executable).stem
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script(f"#! /usr/bin/env {stem} -prearg") as script:
data = self.run_py(
[script, "-postarg"],
@@ -602,7 +607,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
def test_search_path_exe(self):
# Leave the .exe on the name to ensure we don't add it a second time
name = Path(sys.executable).name
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script(f"#! /usr/bin/env {name} -prearg") as script:
data = self.run_py(
[script, "-postarg"],
@@ -612,7 +617,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
def test_recursive_search_path(self):
stem = self.get_py_exe().stem
- with self.py_ini(TEST_PY_COMMANDS):
+ with self.py_ini(TEST_PY_DEFAULTS):
with self.script(f"#! /usr/bin/env {stem}") as script:
data = self.run_py(
[script],
@@ -673,3 +678,21 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
f'"{script.parent}\\some\\ random app" -witharg {script}',
data["stdout"].strip(),
)
+
+ def test_literal_shebang_command(self):
+ with self.py_ini(TEST_PY_COMMANDS):
+ with self.script('#! test-command arg1') as script:
+ data = self.run_py([script])
+ self.assertEqual(
+ f"TEST_EXE.exe arg1 {script}",
+ data["stdout"].strip(),
+ )
+
+ def test_literal_shebang_invalid_template(self):
+ with self.script('#! /usr/bin/not-python arg1') as script:
+ data = self.run_py([script])
+ expect = script.parent / "/usr/bin/not-python"
+ self.assertEqual(
+ f"{expect} arg1 {script}",
+ data["stdout"].strip(),
+ )