[Python-checkins] cpython (3.2): #11963: remove human verification from test_parser and test_subprocess.

ezio.melotti python-checkins at python.org
Mon Mar 11 05:03:22 CET 2013


http://hg.python.org/cpython/rev/222505a5aeac
changeset:   82595:222505a5aeac
branch:      3.2
parent:      82579:64b87578c071
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Mon Mar 11 05:53:34 2013 +0200
summary:
  #11963: remove human verification from test_parser and test_subprocess.

files:
  Lib/test/test_subprocess.py |  48 ++++++++++++++++++------
  Misc/NEWS                   |   2 +
  2 files changed, 38 insertions(+), 12 deletions(-)


diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -157,16 +157,27 @@
         self.assertEqual(p.stdin, None)
 
     def test_stdout_none(self):
-        # .stdout is None when not redirected
-        p = subprocess.Popen([sys.executable, "-c",
-                             'print("    this bit of output is from a '
-                             'test of stdout in a different '
-                             'process ...")'],
-                             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
-        self.addCleanup(p.stdin.close)
+        # .stdout is None when not redirected, and the child's stdout will
+        # be inherited from the parent.  In order to test this we run a
+        # subprocess in a subprocess:
+        # this_test
+        #   \-- subprocess created by this test (parent)
+        #          \-- subprocess created by the parent subprocess (child)
+        # The parent doesn't specify stdout, so the child will use the
+        # parent's stdout.  This test checks that the message printed by the
+        # child goes to the parent stdout.  The parent also checks that the
+        # child's stdout is None.  See #11963.
+        code = ('import sys; from subprocess import Popen, PIPE;'
+                'p = Popen([sys.executable, "-c", "print(\'test_stdout_none\')"],'
+                '          stdin=PIPE, stderr=PIPE);'
+                'p.wait(); assert p.stdout is None;')
+        p = subprocess.Popen([sys.executable, "-c", code],
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
         self.addCleanup(p.stderr.close)
-        p.wait()
-        self.assertEqual(p.stdout, None)
+        out, err = p.communicate()
+        self.assertEqual(p.returncode, 0, err)
+        self.assertEqual(out.rstrip(), b'test_stdout_none')
 
     def test_stderr_none(self):
         # .stderr is None when not redirected
@@ -406,9 +417,22 @@
 
     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(), b'.\n'))"
-        rc = subprocess.call([sys.executable, "-c", cmd], stdout=1)
-        self.assertEqual(rc, 2)
+        # To avoid printing the text on stdout, we do something similar to
+        # test_stdout_none (see above).  The parent subprocess calls the child
+        # subprocess passing stdout=1, and this test uses stdout=PIPE in
+        # order to capture and check the output of the parent. See #11963.
+        code = ('import sys, subprocess; '
+                'rc = subprocess.call([sys.executable, "-c", '
+                '    "import os, sys; sys.exit(os.write(sys.stdout.fileno(), '
+                     'b\'test with stdout=1\'))"], stdout=1); '
+                'assert rc == 18')
+        p = subprocess.Popen([sys.executable, "-c", code],
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        out, err = p.communicate()
+        self.assertEqual(p.returncode, 0, err)
+        self.assertEqual(out.rstrip(), b'test with stdout=1')
 
     def test_env(self):
         newenv = os.environ.copy()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -955,6 +955,8 @@
 Tests
 -----
 
+- Issue #11963: remove human verification from test_parser and test_subprocess.
+
 - Issue #11732: add a new suppress_crash_popup() context manager to test.support
   that disables crash popups on Windows and use it in test_capi.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list