cpython: 862430c68fec (original) (raw)
Mercurial > cpython
changeset 79598:862430c68fec 3.3
Issue #16115: Improve testing of the executable argument to subprocess.Popen(). [#16115]
Chris Jerdonek chris.jerdonek@gmail.com | |
---|---|
date | Mon, 08 Oct 2012 15:56:43 -0700 |
parents | ef183e71268a |
children | 1b37fc50dc1b ef90c5e482f4 |
files | Lib/test/test_subprocess.py Misc/NEWS |
diffstat | 2 files changed, 30 insertions(+), 10 deletions(-)[+] [-] Lib/test/test_subprocess.py 37 Misc/NEWS 3 |
line wrap: on
line diff
--- 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[](#l1.8)
# whenever python is found.[](#l1.9)
args = pre_args + ["import sys; sys.exit(47)"][](#l1.10)
p = subprocess.Popen(args, **kwargs)[](#l1.11)
p.wait()[](#l1.12)
self.assertEqual(47, p.returncode)[](#l1.13)
- def test_executable(self):
# Check that the executable argument works.[](#l1.16)
self._assert_python(["doesnotexist", "-c"], executable=sys.executable)[](#l1.17)
- def test_executable_takes_precedence(self):
# Check that the executable argument takes precedence over args[0].[](#l1.20)
#[](#l1.21)
# Verify first that the call succeeds without the executable arg.[](#l1.22)
pre_args = [sys.executable, "-c"][](#l1.23)
self._assert_python(pre_args)[](#l1.24)
self.assertRaises(FileNotFoundError, self._assert_python, pre_args,[](#l1.25)
executable="doesnotexist")[](#l1.26)
- @unittest.skipIf(mswindows, "executable argument replaces shell")
- def test_executable_replaces_shell(self):
# Check that the executable argument replaces the default shell[](#l1.30)
# when shell=True.[](#l1.31)
self._assert_python([], executable=sys.executable, shell=True)[](#l1.32)
+ # 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][](#l1.42)
# For a normal installation, it should work without 'cwd'[](#l1.43)
# argument. For test runs in the build directory, see #7774.[](#l1.44)
python_dir = os.path.dirname(os.path.realpath(sys.executable))[](#l1.45)
p = subprocess.Popen(["nonexistent","-c",'import sys; sys.exit(42)'],[](#l1.46)
executable=sys.executable, cwd=python_dir)[](#l1.47)
p.wait()[](#l1.48)
self.assertEqual(p.returncode, 42)[](#l1.49)
- def test_stdin_pipe(self): # stdin redirection p = subprocess.Popen([sys.executable, "-c",
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -100,6 +100,9 @@ Library Tests ----- +- Issue #16115: Add some tests for the executable argument to