diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2008-12-04 20:21:09 +0000 |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-12-04 20:21:09 +0000 |
commit | 97f49f4be7ab6d4b570029be4b4439cc29be2f74 (patch) | |
tree | cc0749f51c02c4450f041899410a529a025aa491 /Lib/test/test_subprocess.py | |
parent | 32d1408192c80f072afdf92ca3ab0ef6622387e7 (diff) | |
download | cpython-git-97f49f4be7ab6d4b570029be4b4439cc29be2f74.tar.gz |
Adds a subprocess.check_call_output() function to return the output from a
process on success or raise an exception on error.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r-- | Lib/test/test_subprocess.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index e7ba26fae1..878b79bd95 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -72,6 +72,40 @@ class ProcessTestCase(unittest.TestCase): else: self.fail("Expected CalledProcessError") + def test_check_call_output(self): + # check_call_output() function with zero return code + output = subprocess.check_call_output( + [sys.executable, "-c", "print 'BDFL'"]) + self.assertTrue('BDFL' in output) + + def test_check_call_output_nonzero(self): + # check_call() function with non-zero return code + try: + subprocess.check_call_output( + [sys.executable, "-c", "import sys; sys.exit(5)"]) + except subprocess.CalledProcessError, e: + self.assertEqual(e.returncode, 5) + else: + self.fail("Expected CalledProcessError") + + def test_check_call_output_stderr(self): + # check_call_output() function stderr redirected to stdout + output = subprocess.check_call_output( + [sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"], + stderr=subprocess.STDOUT) + self.assertTrue('BDFL' in output) + + def test_check_call_output_stdout_arg(self): + # check_call_output() function stderr redirected to stdout + try: + output = subprocess.check_call_output( + [sys.executable, "-c", "print 'will not be run'"], + stdout=sys.stdout) + except ValueError, e: + self.assertTrue('stdout' in e.args[0]) + else: + self.fail("Expected ValueError when stdout arg supplied.") + def test_call_kwargs(self): # call() function with keyword args newenv = os.environ.copy() |