diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-12 22:16:28 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-12 22:16:28 (GMT) |
commit | 00dd182b8ec1629a35cb6e9d551dedff6b7149f7 (patch) | |
tree | 733a51f75a7d40a5d3f395fb609348d0ae4eeb66 /Lib | |
parent | b00d0c49448c48b6ddbd85f1328edf8794ae20f7 (diff) | |
parent | 7c4048918053e457eadaf76f2a1906d2cff879f2 (diff) | |
download | cpython-00dd182b8ec1629a35cb6e9d551dedff6b7149f7.zip cpython-00dd182b8ec1629a35cb6e9d551dedff6b7149f7.tar.gz cpython-00dd182b8ec1629a35cb6e9d551dedff6b7149f7.tar.bz2 |
Issue #12062: Fix a flushing bug when doing a certain type of I/O sequence
on a file opened in read+write mode (namely: reading, seeking a bit forward,
writing, then seeking before the previous write but still within buffered
data, and writing again).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index b665a6c..dac30cb 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1490,6 +1490,32 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest): self.assertEqual(s, b"A" + b"B" * overwrite_size + b"A" * (9 - overwrite_size)) + def test_write_rewind_write(self): + # Various combinations of reading / writing / seeking backwards / writing again + def mutate(bufio, pos1, pos2): + assert pos2 >= pos1 + # Fill the buffer + bufio.seek(pos1) + bufio.read(pos2 - pos1) + bufio.write(b'\x02') + # This writes earlier than the previous write, but still inside + # the buffer. + bufio.seek(pos1) + bufio.write(b'\x01') + + b = b"\x80\x81\x82\x83\x84" + for i in range(0, len(b)): + for j in range(i, len(b)): + raw = self.BytesIO(b) + bufio = self.tp(raw, 100) + mutate(bufio, i, j) + bufio.flush() + expected = bytearray(b) + expected[j] = 2 + expected[i] = 1 + self.assertEqual(raw.getvalue(), expected, + "failed result for i=%d, j=%d" % (i, j)) + def test_truncate_after_read_or_write(self): raw = self.BytesIO(b"A" * 10) bufio = self.tp(raw, 100) |