cpython: d25749c32bb4 (original) (raw)
--- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -150,16 +150,27 @@ class ProcessTestCase(BaseTestCase): self.assertEqual(p.stdin, None) def test_stdout_none(self):
# .stdout is None when not redirected[](#l1.7)
p = subprocess.Popen([sys.executable, "-c",[](#l1.8)
'print " this bit of output is from a '[](#l1.9)
'test of stdout in a different '[](#l1.10)
'process ..."'],[](#l1.11)
stdin=subprocess.PIPE, stderr=subprocess.PIPE)[](#l1.12)
self.addCleanup(p.stdin.close)[](#l1.13)
# .stdout is None when not redirected, and the child's stdout will[](#l1.14)
# be inherited from the parent. In order to test this we run a[](#l1.15)
# subprocess in a subprocess:[](#l1.16)
# this_test[](#l1.17)
# \-- subprocess created by this test (parent)[](#l1.18)
# \-- subprocess created by the parent subprocess (child)[](#l1.19)
# The parent doesn't specify stdout, so the child will use the[](#l1.20)
# parent's stdout. This test checks that the message printed by the[](#l1.21)
# child goes to the parent stdout. The parent also checks that the[](#l1.22)
# child's stdout is None. See #11963.[](#l1.23)
code = ('import sys; from subprocess import Popen, PIPE;'[](#l1.24)
'p = Popen([sys.executable, "-c", "print \'test_stdout_none\'"],'[](#l1.25)
' stdin=PIPE, stderr=PIPE);'[](#l1.26)
'p.wait(); assert p.stdout is None;')[](#l1.27)
p = subprocess.Popen([sys.executable, "-c", code],[](#l1.28)
stdout=subprocess.PIPE, stderr=subprocess.PIPE)[](#l1.29)
self.addCleanup(p.stdout.close)[](#l1.30) self.addCleanup(p.stderr.close)[](#l1.31)
p.wait()[](#l1.32)
self.assertEqual(p.stdout, None)[](#l1.33)
out, err = p.communicate()[](#l1.34)
self.assertEqual(p.returncode, 0, err)[](#l1.35)
self.assertEqual(out.rstrip(), 'test_stdout_none')[](#l1.36)
def test_stderr_none(self): # .stderr is None when not redirected @@ -308,9 +319,22 @@ class ProcessTestCase(BaseTestCase): def test_stdout_filedes_of_stdout(self): # stdout is set to 1 (#1531862).
cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), '.\n'))"[](#l1.44)
rc = subprocess.call([sys.executable, "-c", cmd], stdout=1)[](#l1.45)
self.assertEqual(rc, 2)[](#l1.46)
# To avoid printing the '.\n' on stdout, we do something similar to[](#l1.47)
# test_stdout_none (see above). The parent subprocess calls the child[](#l1.48)
# subprocess passing stdout=1, and this test uses stdout=PIPE in[](#l1.49)
# order to capture and check the output of the parent. See #11963.[](#l1.50)
code = ('import sys, subprocess; '[](#l1.51)
'rc = subprocess.call([sys.executable, "-c", '[](#l1.52)
' "import os, sys; sys.exit(os.write(sys.stdout.fileno(), '[](#l1.53)
'\'.\\\\n\'))"], stdout=1); '[](#l1.54)
'assert rc == 2')[](#l1.55)
p = subprocess.Popen([sys.executable, "-c", code],[](#l1.56)
stdout=subprocess.PIPE, stderr=subprocess.PIPE)[](#l1.57)
self.addCleanup(p.stdout.close)[](#l1.58)
self.addCleanup(p.stderr.close)[](#l1.59)
out, err = p.communicate()[](#l1.60)
self.assertEqual(p.returncode, 0, err)[](#l1.61)
self.assertEqual(out, '.\n')[](#l1.62)
def test_cwd(self): tmpdir = tempfile.gettempdir()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -812,6 +812,8 @@ Extension Modules Tests ----- +- Issue #11963: remove human verification from test_parser and test_subprocess. +