summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-10-08 19:37:33 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-10-08 19:37:33 (GMT)
commitc6f9b2b7f5f3640ce8aeac4aff67f75821891d81 (patch)
tree4ea6927932eabc220c9781081806b10d80743d3a /Lib/test
parentea200dba822736a0ad717c34fb14fcb3441bff82 (diff)
downloadcpython-c6f9b2b7f5f3640ce8aeac4aff67f75821891d81.zip
cpython-c6f9b2b7f5f3640ce8aeac4aff67f75821891d81.tar.gz
cpython-c6f9b2b7f5f3640ce8aeac4aff67f75821891d81.tar.bz2
Issue #28162: Fixes Ctrl+Z handling in console readall()
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_winconsoleio.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py
index f2cccbc..b1a2f7a 100644
--- a/Lib/test/test_winconsoleio.py
+++ b/Lib/test/test_winconsoleio.py
@@ -107,16 +107,15 @@ class WindowsConsoleIOTests(unittest.TestCase):
source = 'ϼўТλФЙ\r\n'.encode('utf-16-le')
expected = 'ϼўТλФЙ\r\n'.encode('utf-8')
for read_count in range(1, 16):
- stdin = open('CONIN$', 'rb', buffering=0)
- write_input(stdin, source)
+ with open('CONIN$', 'rb', buffering=0) as stdin:
+ write_input(stdin, source)
- actual = b''
- while not actual.endswith(b'\n'):
- b = stdin.read(read_count)
- actual += b
+ actual = b''
+ while not actual.endswith(b'\n'):
+ b = stdin.read(read_count)
+ actual += b
- self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
- stdin.close()
+ self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
def test_partial_surrogate_reads(self):
# Test that reading less than 1 full character works when stdin
@@ -125,17 +124,24 @@ class WindowsConsoleIOTests(unittest.TestCase):
source = '\U00101FFF\U00101001\r\n'.encode('utf-16-le')
expected = '\U00101FFF\U00101001\r\n'.encode('utf-8')
for read_count in range(1, 16):
- stdin = open('CONIN$', 'rb', buffering=0)
- write_input(stdin, source)
+ with open('CONIN$', 'rb', buffering=0) as stdin:
+ write_input(stdin, source)
- actual = b''
- while not actual.endswith(b'\n'):
- b = stdin.read(read_count)
- actual += b
+ actual = b''
+ while not actual.endswith(b'\n'):
+ b = stdin.read(read_count)
+ actual += b
- self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
- stdin.close()
+ self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
+ def test_ctrl_z(self):
+ with open('CONIN$', 'rb', buffering=0) as stdin:
+ source = '\xC4\x1A\r\n'.encode('utf-16-le')
+ expected = '\xC4'.encode('utf-8')
+ write_input(stdin, source)
+ a, b = stdin.read(1), stdin.readall()
+ self.assertEqual(expected[0:1], a)
+ self.assertEqual(expected[1:], b)
if __name__ == "__main__":
unittest.main()