diff options
author | andyclegg <andy2.0@gmail.com> | 2017-10-23 02:01:19 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2017-10-23 02:01:19 (GMT) |
commit | 7fed7bd8bb628f0f09c6011871a4ce68afb41b18 (patch) | |
tree | a89c99e634133cae2dc33671182f8f4ae0723226 /Lib/test | |
parent | ae3087c6382011c47db82fea4d05f8bbf514265d (diff) | |
download | cpython-7fed7bd8bb628f0f09c6011871a4ce68afb41b18.zip cpython-7fed7bd8bb628f0f09c6011871a4ce68afb41b18.tar.gz cpython-7fed7bd8bb628f0f09c6011871a4ce68afb41b18.tar.bz2 |
bpo-31756: subprocess.run should alias universal_newlines to text (#4049)
Improve human friendliness of the Popen API: Add text=False as a
keyword-only argument to subprocess.Popen along with a Popen
attribute .text_mode and set this based on the
encoding/errors/universal_newlines/text arguments.
The universal_newlines parameter and attribute are maintained for
backwards compatibility.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_subprocess.py | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 3ba5c02..fff1b0d 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -845,41 +845,44 @@ class ProcessTestCase(BaseTestCase): self.assertEqual(stdout, b"bananasplit") self.assertStderrEqual(stderr, b"") - def test_universal_newlines(self): - p = subprocess.Popen([sys.executable, "-c", - 'import sys,os;' + SETBINARY + - 'buf = sys.stdout.buffer;' - 'buf.write(sys.stdin.readline().encode());' - 'buf.flush();' - 'buf.write(b"line2\\n");' - 'buf.flush();' - 'buf.write(sys.stdin.read().encode());' - 'buf.flush();' - 'buf.write(b"line4\\n");' - 'buf.flush();' - 'buf.write(b"line5\\r\\n");' - 'buf.flush();' - 'buf.write(b"line6\\r");' - 'buf.flush();' - 'buf.write(b"\\nline7");' - 'buf.flush();' - 'buf.write(b"\\nline8");'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - universal_newlines=1) - with p: - p.stdin.write("line1\n") - p.stdin.flush() - self.assertEqual(p.stdout.readline(), "line1\n") - p.stdin.write("line3\n") - p.stdin.close() - self.addCleanup(p.stdout.close) - self.assertEqual(p.stdout.readline(), - "line2\n") - self.assertEqual(p.stdout.read(6), - "line3\n") - self.assertEqual(p.stdout.read(), - "line4\nline5\nline6\nline7\nline8") + def test_universal_newlines_and_text(self): + args = [ + sys.executable, "-c", + 'import sys,os;' + SETBINARY + + 'buf = sys.stdout.buffer;' + 'buf.write(sys.stdin.readline().encode());' + 'buf.flush();' + 'buf.write(b"line2\\n");' + 'buf.flush();' + 'buf.write(sys.stdin.read().encode());' + 'buf.flush();' + 'buf.write(b"line4\\n");' + 'buf.flush();' + 'buf.write(b"line5\\r\\n");' + 'buf.flush();' + 'buf.write(b"line6\\r");' + 'buf.flush();' + 'buf.write(b"\\nline7");' + 'buf.flush();' + 'buf.write(b"\\nline8");'] + + for extra_kwarg in ('universal_newlines', 'text'): + p = subprocess.Popen(args, **{'stdin': subprocess.PIPE, + 'stdout': subprocess.PIPE, + extra_kwarg: True}) + with p: + p.stdin.write("line1\n") + p.stdin.flush() + self.assertEqual(p.stdout.readline(), "line1\n") + p.stdin.write("line3\n") + p.stdin.close() + self.addCleanup(p.stdout.close) + self.assertEqual(p.stdout.readline(), + "line2\n") + self.assertEqual(p.stdout.read(6), + "line3\n") + self.assertEqual(p.stdout.read(), + "line4\nline5\nline6\nline7\nline8") def test_universal_newlines_communicate(self): # universal newlines through communicate() |