diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-02-23 12:10:23 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-02-23 12:10:23 (GMT) |
commit | 02bfdb3f791a007801f2d14ed11b21bd6498ff9c (patch) | |
tree | 86835246c57c673166e4fe00911101195326428c /Lib/test/test_cmd_line.py | |
parent | 9f6cbe09cc88be914600306b34ac3d0025738465 (diff) | |
download | cpython-02bfdb3f791a007801f2d14ed11b21bd6498ff9c.zip cpython-02bfdb3f791a007801f2d14ed11b21bd6498ff9c.tar.gz cpython-02bfdb3f791a007801f2d14ed11b21bd6498ff9c.tar.bz2 |
Merged revisions 88530 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r88530 | victor.stinner | 2011-02-23 13:07:37 +0100 (mer., 23 févr. 2011) | 4 lines
Issue #11272: Fix input() and sys.stdin for Windows newline
On Windows, input() strips '\r' (and not only '\n'), and sys.stdin uses
universal newline (replace '\r\n' by '\n').
........
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r-- | Lib/test/test_cmd_line.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index b21b61e..c4e3adf 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -6,6 +6,7 @@ import test.support, unittest import os import sys import subprocess +import tempfile from test.script_helper import spawn_python, kill_python, assert_python_ok, assert_python_failure @@ -239,6 +240,31 @@ class CmdLineTest(unittest.TestCase): escaped = repr(text).encode(encoding, 'backslashreplace') self.assertIn(escaped, data) + def check_input(self, code, expected): + with tempfile.NamedTemporaryFile("wb+") as stdin: + sep = os.linesep.encode('ASCII') + stdin.write(sep.join((b'abc', b'def'))) + stdin.flush() + stdin.seek(0) + with subprocess.Popen( + (sys.executable, "-c", code), + stdin=stdin, stdout=subprocess.PIPE) as proc: + stdout, stderr = proc.communicate() + self.assertEqual(stdout.rstrip(), expected) + + def test_stdin_readline(self): + # Issue #11272: check that sys.stdin.readline() replaces '\r\n' by '\n' + # on Windows (sys.stdin is opened in binary mode) + self.check_input( + "import sys; print(repr(sys.stdin.readline()))", + b"'abc\\n'") + + def test_builtin_input(self): + # Issue #11272: check that input() strips newlines ('\n' or '\r\n') + self.check_input( + "print(repr(input()))", + b"'abc'") + def test_main(): test.support.run_unittest(CmdLineTest) |