mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merged revisions 67511,67536-67537,67543 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67511 | vinay.sajip | 2008-12-04 00:22:58 +0100 (Thu, 04 Dec 2008) | 1 line Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging. ........ r67536 | gregory.p.smith | 2008-12-04 21:21:09 +0100 (Thu, 04 Dec 2008) | 3 lines Adds a subprocess.check_call_output() function to return the output from a process on success or raise an exception on error. ........ r67537 | vinay.sajip | 2008-12-04 21:32:18 +0100 (Thu, 04 Dec 2008) | 1 line Took Nick Coghlan's advice about importing warnings globally in logging, to avoid the possibility of race conditions: "This could deadlock if a thread spawned as a side effect of importing a module happens to trigger a warning. warnings is pulled into sys.modules as part of the interpreter startup - having a global 'import warnings' shouldn't have any real effect on logging's import time." ........ r67543 | gregory.p.smith | 2008-12-05 03:27:01 +0100 (Fri, 05 Dec 2008) | 2 lines rename the new check_call_output to check_output. its less ugly. ........
This commit is contained in:
parent
2080ea5f4b
commit
f9734076cf
7 changed files with 239 additions and 18 deletions
|
@ -73,6 +73,40 @@ class ProcessTestCase(unittest.TestCase):
|
|||
else:
|
||||
self.fail("Expected CalledProcessError")
|
||||
|
||||
def test_check_output(self):
|
||||
# check_output() function with zero return code
|
||||
output = subprocess.check_output(
|
||||
[sys.executable, "-c", "print('BDFL')"])
|
||||
self.assertTrue(b'BDFL' in output)
|
||||
|
||||
def test_check_output_nonzero(self):
|
||||
# check_call() function with non-zero return code
|
||||
try:
|
||||
subprocess.check_output(
|
||||
[sys.executable, "-c", "import sys; sys.exit(5)"])
|
||||
except subprocess.CalledProcessError as e:
|
||||
self.assertEqual(e.returncode, 5)
|
||||
else:
|
||||
self.fail("Expected CalledProcessError")
|
||||
|
||||
def test_check_output_stderr(self):
|
||||
# check_output() function stderr redirected to stdout
|
||||
output = subprocess.check_output(
|
||||
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
|
||||
stderr=subprocess.STDOUT)
|
||||
self.assertTrue(b'BDFL' in output)
|
||||
|
||||
def test_check_output_stdout_arg(self):
|
||||
# check_output() function stderr redirected to stdout
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
[sys.executable, "-c", "print('will not be run')"],
|
||||
stdout=sys.stdout)
|
||||
except ValueError as 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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue