diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-01 20:08:46 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-01 20:08:46 (GMT) |
commit | 7ffa196dce8db3010bce3e550078ed455a30e851 (patch) | |
tree | ec5119d3f4e2b23c8c1b07af8c5e453f6f4a7949 /Lib | |
parent | 7fb6f5121a42136f35c561c408091cd043f6340d (diff) | |
download | cpython-7ffa196dce8db3010bce3e550078ed455a30e851.zip cpython-7ffa196dce8db3010bce3e550078ed455a30e851.tar.gz cpython-7ffa196dce8db3010bce3e550078ed455a30e851.tar.bz2 |
Issue #8397: Raise an error when attempting to mix iteration and regular
reads on a BZ2File object, rather than returning incorrect results.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_bz2.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index 63b3009..0826458 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -304,6 +304,24 @@ class BZ2FileTest(BaseTest): finally: f.close() + def testMixedIterationReads(self): + # Issue #8397: mixed iteration and reads should be forbidden. + f = bz2.BZ2File(self.filename, 'wb') + try: + # The internal buffer size is hard-wired to 8192 bytes, we must + # write out more than that for the test to stop half through + # the buffer. + f.write(self.TEXT * 100) + finally: + f.close() + f = bz2.BZ2File(self.filename, 'rb') + try: + next(f) + self.assertRaises(ValueError, f.read) + self.assertRaises(ValueError, f.readline) + self.assertRaises(ValueError, f.readlines) + finally: + f.close() class BZ2CompressorTest(BaseTest): def testCompress(self): |