summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zlib.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-11-11 01:21:22 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-11-11 01:21:22 (GMT)
commitdd1253abdd8564b095f24107547be0b8ce91e653 (patch)
tree7eee961bf90aa457337ca1f852667db346f06da8 /Lib/test/test_zlib.py
parent73e9bd4d259c3c213347e45d4bb5bf20fb51c7f4 (diff)
parentee7889dec321654d1c50448de7987e1841dd3ad5 (diff)
downloadcpython-dd1253abdd8564b095f24107547be0b8ce91e653.zip
cpython-dd1253abdd8564b095f24107547be0b8ce91e653.tar.gz
cpython-dd1253abdd8564b095f24107547be0b8ce91e653.tar.bz2
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Additionally, fix a bug where a MemoryError in allocating a bytes object could leave the decompressor object in an invalid state (with its unconsumed_tail member being NULL). Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/test/test_zlib.py')
-rw-r--r--Lib/test/test_zlib.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index b6a60f4..f5180e0 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -490,16 +490,28 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
def test_decompress_unused_data(self):
# Repeated calls to decompress() after EOF should accumulate data in
# dco.unused_data, instead of just storing the arg to the last call.
- x = zlib.compress(HAMLET_SCENE) + HAMLET_SCENE
- for step in 1, 2, 100:
- dco = zlib.decompressobj()
- data = b''.join(dco.decompress(x[i : i + step])
- for i in range(0, len(x), step))
- data += dco.flush()
-
- self.assertTrue(dco.eof)
- self.assertEqual(data, HAMLET_SCENE)
- self.assertEqual(dco.unused_data, HAMLET_SCENE)
+ source = b'abcdefghijklmnopqrstuvwxyz'
+ remainder = b'0123456789'
+ y = zlib.compress(source)
+ x = y + remainder
+ for maxlen in 0, 1000:
+ for step in 1, 2, len(y), len(x):
+ dco = zlib.decompressobj()
+ data = b''
+ for i in range(0, len(x), step):
+ if i < len(y):
+ self.assertEqual(dco.unused_data, b'')
+ if maxlen == 0:
+ data += dco.decompress(x[i : i + step])
+ self.assertEqual(dco.unconsumed_tail, b'')
+ else:
+ data += dco.decompress(
+ dco.unconsumed_tail + x[i : i + step], maxlen)
+ data += dco.flush()
+ self.assertTrue(dco.eof)
+ self.assertEqual(data, source)
+ self.assertEqual(dco.unconsumed_tail, b'')
+ self.assertEqual(dco.unused_data, remainder)
if hasattr(zlib.compressobj(), "copy"):
def test_compresscopy(self):