diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-23 19:46:35 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-23 19:46:35 (GMT) |
commit | e96ec6810184f5daacb2d47ab8801365c99bb206 (patch) | |
tree | 39473d0363b97a0f92fa50e512125041cecc6296 /Lib/test/test_io.py | |
parent | ce7e51e8f615e6bc7dec1b33b23b1414c6dc27ea (diff) | |
download | cpython-e96ec6810184f5daacb2d47ab8801365c99bb206.zip cpython-e96ec6810184f5daacb2d47ab8801365c99bb206.tar.gz cpython-e96ec6810184f5daacb2d47ab8801365c99bb206.tar.bz2 |
Issue #12591: Allow io.TextIOWrapper to work with raw IO objects (without
a read1() method), and add an undocumented *write_through* parameter to
mandate unbuffered writes.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 39fda2b..0ca621c 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2307,6 +2307,27 @@ class TextIOWrapperTest(unittest.TestCase): with self.assertRaises(AttributeError): txt.buffer = buf + def test_rawio(self): + # Issue #12591: TextIOWrapper must work with raw I/O objects, so + # that subprocess.Popen() can have the required unbuffered + # semantics with universal_newlines=True. + raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n']) + txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n') + # Reads + self.assertEqual(txt.read(4), 'abcd') + self.assertEqual(txt.readline(), 'efghi\n') + self.assertEqual(list(txt), ['jkl\n', 'opq\n']) + + def test_rawio_write_through(self): + # Issue #12591: with write_through=True, writes don't need a flush + raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n']) + txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n', + write_through=True) + txt.write('1') + txt.write('23\n4') + txt.write('5') + self.assertEqual(b''.join(raw._write_stack), b'123\n45') + class CTextIOWrapperTest(TextIOWrapperTest): def test_initialization(self): |