diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-08-06 20:52:43 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-08-06 20:52:43 (GMT) |
commit | 0473e56964ae9d041cfb0c3c8e09994cb58b675a (patch) | |
tree | 8e7ad0bb81f72d3200028ea50def9fe4a0871d89 /Lib/test/test_io.py | |
parent | 825b993542563d76b08ca7b01729b20837ba9245 (diff) | |
download | cpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.zip cpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.tar.gz cpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.tar.bz2 |
Merged revisions 74338 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r74338 | antoine.pitrou | 2009-08-06 22:29:56 +0200 (jeu., 06 août 2009) | 14 lines
Merged revisions 74336 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74336 | antoine.pitrou | 2009-08-06 22:18:29 +0200 (jeu., 06 août 2009) | 8 lines
Issue #6629: Fix a data corruption issue in the new `io` package, which could
occur when writing to a BufferedRandom object (e.g. a file opened in "rb+" or
"wb+" mode) after having buffered a certain amount of data for reading. This
bug was not present in the pure Python implementation.
Yes, this is a serious issue.
........
................
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 729c0ca..407a8a4 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1328,6 +1328,26 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest): bufio.readinto(bytearray(1)) self.check_writes(_read) + def test_write_after_readahead(self): + # Issue #6629: writing after the buffer was filled by readahead should + # first rewind the raw stream. + for overwrite_size in [1, 5]: + raw = self.BytesIO(b"A" * 10) + bufio = self.tp(raw, 4) + # Trigger readahead + self.assertEqual(bufio.read(1), b"A") + self.assertEqual(bufio.tell(), 1) + # Overwriting should rewind the raw stream if it needs so + bufio.write(b"B" * overwrite_size) + self.assertEqual(bufio.tell(), overwrite_size + 1) + # If the write size was smaller than the buffer size, flush() and + # check that rewind happens. + bufio.flush() + self.assertEqual(bufio.tell(), overwrite_size + 1) + s = raw.getvalue() + self.assertEqual(s, + b"A" + b"B" * overwrite_size + b"A" * (9 - overwrite_size)) + def test_misbehaved_io(self): BufferedReaderTest.test_misbehaved_io(self) BufferedWriterTest.test_misbehaved_io(self) |