From 894375a2fdb872c36810bd4d010dcb2cbd8f8c9c Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 5 Aug 2012 00:15:06 +0200 Subject: [PATCH 1/2] Fix test_sys under Windows (issue #13119) --- Lib/test/test_sys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index b055fccbcbd..a52767a1106 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -523,7 +523,8 @@ class SysModuleTest(unittest.TestCase): p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], stdout = subprocess.PIPE, env=env) out = p.communicate()[0].strip() - self.assertEqual(out, "\xa2\n".encode("cp424")) + expected = ("\xa2" + os.linesep).encode("cp424") + self.assertEqual(out, expected) env["PYTHONIOENCODING"] = "ascii:replace" p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], From ec2d26930cf255dc95a325a0d3c6da7927398a96 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 5 Aug 2012 00:23:40 +0200 Subject: [PATCH 2/2] Fix universal newlines test to avoid the newline translation done by sys.stdout. --- Lib/test/test_subprocess.py | 54 +++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 6150e88c54c..52de5c064c8 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -476,21 +476,22 @@ class ProcessTestCase(BaseTestCase): def test_universal_newlines(self): p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write(sys.stdin.readline());' - 'sys.stdout.flush();' - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write(sys.stdin.read());' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + '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) @@ -510,17 +511,18 @@ class ProcessTestCase(BaseTestCase): # universal newlines through communicate() p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + 'buf = sys.stdout.buffer;' + 'buf.write(b"line2\\n");' + '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");'], stderr=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=1)