[Python-Dev] cpython: Add yet another test for subprocess.Popen.communicate (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Thu Aug 16 00:25:42 CEST 2012


On Wed, 15 Aug 2012 21:54:06 +0200 (CEST) andrew.svetlov <python-checkins at python.org> wrote:

diff --git a/Lib/test/testsubprocess.py b/Lib/test/testsubprocess.py --- a/Lib/test/testsubprocess.py +++ b/Lib/test/testsubprocess.py @@ -645,6 +645,34 @@ p.communicate() self.assertEqual(p.returncode, 0) + def testuniversalnewlinescommunicatestdinstdoutstderr(self): + # universal newlines through communicate(), with only stdin + p = subprocess.Popen([sys.executable, "-c", + 'import sys,os;' + SETBINARY + '''\nif True: + s = sys.stdin.readline() + sys.stdout.write(s) + sys.stdout.write("line2\r") + sys.stderr.write("eline2\n") + s = sys.stdin.read() + sys.stdout.write(s+"line4\n") + sys.stdout.write(s+"line5\r\n") + sys.stderr.write("eline6\n") + sys.stderr.write("eline7\r") + sys.stderr.write("eline8\r\n") + '''],

This test is wrong. You need to write your test data as binary data on the binary output streams, as in the other tests. Using the text output streams introduces a spurious line ending conversion, which makes the test fail under Windows: http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/486

+ # Python debug build push something like "[42442 refs]\n" + # to stderr at exit of subprocess. + self.assertTrue(stderr.startswith("eline2\neline6\neline7\neline8\n"))

You should use self.assertStderrEqual() instead.

Regards

Antoine.

-- Software development and contracting: http://pro.pitrou.net



More information about the Python-Dev mailing list