summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-10-08 22:56:43 (GMT)
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-10-08 22:56:43 (GMT)
commit776cb199bc2cead241b13b08827e225921252d2b (patch)
tree7d2ee6644d533bd68c3e9324a4bb57545a892778 /Lib/test/test_subprocess.py
parent101591e9d52d3057bfafc01811ef215c3bf1745d (diff)
downloadcpython-776cb199bc2cead241b13b08827e225921252d2b.zip
cpython-776cb199bc2cead241b13b08827e225921252d2b.tar.gz
cpython-776cb199bc2cead241b13b08827e225921252d2b.tar.bz2
Issue #16115: Improve testing of the executable argument to subprocess.Popen().
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 6fc6108..3dbef13 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -192,6 +192,33 @@ class ProcessTestCase(BaseTestCase):
p.wait()
self.assertEqual(p.stderr, None)
+ def _assert_python(self, pre_args, **kwargs):
+ # We include sys.exit() to prevent the test runner from hanging
+ # whenever python is found.
+ args = pre_args + ["import sys; sys.exit(47)"]
+ p = subprocess.Popen(args, **kwargs)
+ p.wait()
+ self.assertEqual(47, p.returncode)
+
+ def test_executable(self):
+ # Check that the executable argument works.
+ self._assert_python(["doesnotexist", "-c"], executable=sys.executable)
+
+ def test_executable_takes_precedence(self):
+ # Check that the executable argument takes precedence over args[0].
+ #
+ # Verify first that the call succeeds without the executable arg.
+ pre_args = [sys.executable, "-c"]
+ self._assert_python(pre_args)
+ self.assertRaises(FileNotFoundError, self._assert_python, pre_args,
+ executable="doesnotexist")
+
+ @unittest.skipIf(mswindows, "executable argument replaces shell")
+ def test_executable_replaces_shell(self):
+ # Check that the executable argument replaces the default shell
+ # when shell=True.
+ self._assert_python([], executable=sys.executable, shell=True)
+
# For use in the test_cwd* tests below.
def _normalize_cwd(self, cwd):
# Normalize an expected cwd (for Tru64 support).
@@ -299,16 +326,6 @@ class ProcessTestCase(BaseTestCase):
# argument. For test runs in the build directory, see #7774.
self._assert_cwd('', "somethingyoudonthave", executable=sys.executable)
- def test_executable_precedence(self):
- # To the precedence of executable argument over args[0]
- # For a normal installation, it should work without 'cwd'
- # argument. For test runs in the build directory, see #7774.
- python_dir = os.path.dirname(os.path.realpath(sys.executable))
- p = subprocess.Popen(["nonexistent","-c",'import sys; sys.exit(42)'],
- executable=sys.executable, cwd=python_dir)
- p.wait()
- self.assertEqual(p.returncode, 42)
-
def test_stdin_pipe(self):
# stdin redirection
p = subprocess.Popen([sys.executable, "-c",