diff options
author | Guido van Rossum <guido@python.org> | 2007-12-06 01:04:26 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-12-06 01:04:26 (GMT) |
commit | f64db9f6db6dc631368faaeaa5547769a01682cc (patch) | |
tree | fe6ff3ed1fb0ed0d3edfe193f303a31a3d93a003 /Lib/test/test_io.py | |
parent | 786720876c4a473284a0324c8e3b43ed87e8f42c (diff) | |
download | cpython-f64db9f6db6dc631368faaeaa5547769a01682cc.zip cpython-f64db9f6db6dc631368faaeaa5547769a01682cc.tar.gz cpython-f64db9f6db6dc631368faaeaa5547769a01682cc.tar.bz2 |
Fix the rest of issue 1400, by introducing a proper implementation of
line buffering. The TextIOWrapper class no longer calls isatty() on
every write() call.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index f5b4a94..87e871b 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -496,6 +496,17 @@ class TextIOWrapperTest(unittest.TestCase): def tearDown(self): test_support.unlink(test_support.TESTFN) + def testLineBuffering(self): + r = io.BytesIO() + b = io.BufferedWriter(r, 1000) + t = io.TextIOWrapper(b, newline="\n", line_buffering=True) + t.write("X") + self.assertEquals(r.getvalue(), b"") # No flush happened + t.write("Y\nZ") + self.assertEquals(r.getvalue(), b"XY\nZ") # All got flushed + t.write("A\rB") + self.assertEquals(r.getvalue(), b"XY\nZA\rB") + def testEncodingErrorsReading(self): # (1) default b = io.BytesIO(b"abc\n\xff\n") @@ -525,13 +536,15 @@ class TextIOWrapperTest(unittest.TestCase): self.assertRaises(UnicodeError, t.write, "\xff") # (3) ignore b = io.BytesIO() - t = io.TextIOWrapper(b, encoding="ascii", errors="ignore", newline="\n") + t = io.TextIOWrapper(b, encoding="ascii", errors="ignore", + newline="\n") t.write("abc\xffdef\n") t.flush() self.assertEquals(b.getvalue(), b"abcdef\n") # (4) replace b = io.BytesIO() - t = io.TextIOWrapper(b, encoding="ascii", errors="replace", newline="\n") + t = io.TextIOWrapper(b, encoding="ascii", errors="replace", + newline="\n") t.write("abc\xffdef\n") t.flush() self.assertEquals(b.getvalue(), b"abc?def\n") |