mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #8397: Raise an error when attempting to mix iteration and regular
reads on a BZ2File object, rather than returning incorrect results.
This commit is contained in:
parent
7fb6f5121a
commit
7ffa196dce
3 changed files with 49 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue