Commit 47ec25d2 authored by Andrew Svetlov's avatar Andrew Svetlov

Brush subprocess tests a bit.

parent 4d16bcce
...@@ -14,6 +14,7 @@ import warnings ...@@ -14,6 +14,7 @@ import warnings
import select import select
import shutil import shutil
import gc import gc
import textwrap
try: try:
import resource import resource
...@@ -622,12 +623,12 @@ class ProcessTestCase(BaseTestCase): ...@@ -622,12 +623,12 @@ class ProcessTestCase(BaseTestCase):
def test_universal_newlines_communicate_stdin(self): def test_universal_newlines_communicate_stdin(self):
# universal newlines through communicate(), with only stdin # universal newlines through communicate(), with only stdin
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys,os;' + SETBINARY + '''\nif True: 'import sys,os;' + SETBINARY + textwrap.dedent('''
s = sys.stdin.readline() s = sys.stdin.readline()
assert s == "line1\\n", repr(s) assert s == "line1\\n", repr(s)
s = sys.stdin.read() s = sys.stdin.read()
assert s == "line3\\n", repr(s) assert s == "line3\\n", repr(s)
'''], ''')],
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
universal_newlines=1) universal_newlines=1)
(stdout, stderr) = p.communicate("line1\nline3\n") (stdout, stderr) = p.communicate("line1\nline3\n")
...@@ -646,24 +647,24 @@ class ProcessTestCase(BaseTestCase): ...@@ -646,24 +647,24 @@ class ProcessTestCase(BaseTestCase):
self.assertEqual(p.returncode, 0) self.assertEqual(p.returncode, 0)
def test_universal_newlines_communicate_stdin_stdout_stderr(self): def test_universal_newlines_communicate_stdin_stdout_stderr(self):
# universal newlines through communicate(), with only stdin # universal newlines through communicate(), with stdin, stdout, stderr
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys,os;' + SETBINARY + '''\nif True: 'import sys,os;' + SETBINARY + textwrap.dedent('''
s = sys.stdin.readline() s = sys.stdin.buffer.readline()
sys.stdout.buffer.write(s.encode()) sys.stdout.buffer.write(s)
sys.stdout.buffer.write(b"line2\\r") sys.stdout.buffer.write(b"line2\\r")
sys.stderr.buffer.write(b"eline2\\n") sys.stderr.buffer.write(b"eline2\\n")
s = sys.stdin.read() s = sys.stdin.buffer.read()
sys.stdout.buffer.write(s.encode()) sys.stdout.buffer.write(s)
sys.stdout.buffer.write(b"line4\\n") sys.stdout.buffer.write(b"line4\\n")
sys.stdout.buffer.write(b"line5\\r\\n") sys.stdout.buffer.write(b"line5\\r\\n")
sys.stderr.buffer.write(b"eline6\\r") sys.stderr.buffer.write(b"eline6\\r")
sys.stderr.buffer.write(b"eline7\\r\\nz") sys.stderr.buffer.write(b"eline7\\r\\nz")
'''], ''')],
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
universal_newlines=1) universal_newlines=True)
self.addCleanup(p.stdout.close) self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close) self.addCleanup(p.stderr.close)
(stdout, stderr) = p.communicate("line1\nline3\n") (stdout, stderr) = p.communicate("line1\nline3\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment