summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_lzma.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-31 06:31:13 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-31 06:31:13 (GMT)
commit88b221935895dd56ebae3a3299897ac9cd0c6eb2 (patch)
treefc6f8764566d5a5e1594002b37b74d019f155ed4 /Lib/test/test_lzma.py
parent13c8f3266a09e19c3c89c118b46b4205bc2a0082 (diff)
parent04f17f103afcee73c65709252b0dba6411df7665 (diff)
downloadcpython-88b221935895dd56ebae3a3299897ac9cd0c6eb2.zip
cpython-88b221935895dd56ebae3a3299897ac9cd0c6eb2.tar.gz
cpython-88b221935895dd56ebae3a3299897ac9cd0c6eb2.tar.bz2
Issue #27517: LZMA compressor and decompressor no longer raise exceptions if
given empty data twice. Patch by Benjamin Fogle.
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r--Lib/test/test_lzma.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
index fdc8e11..d7a8576 100644
--- a/Lib/test/test_lzma.py
+++ b/Lib/test/test_lzma.py
@@ -137,6 +137,21 @@ class CompressorDecompressorTestCase(unittest.TestCase):
self.assertTrue(lzd.eof)
self.assertEqual(lzd.unused_data, b"")
+ def test_decompressor_chunks_empty(self):
+ lzd = LZMADecompressor()
+ out = []
+ for i in range(0, len(COMPRESSED_XZ), 10):
+ self.assertFalse(lzd.eof)
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(COMPRESSED_XZ[i:i+10]))
+ out = b"".join(out)
+ self.assertEqual(out, INPUT)
+ self.assertEqual(lzd.check, lzma.CHECK_CRC64)
+ self.assertTrue(lzd.eof)
+ self.assertEqual(lzd.unused_data, b"")
+
def test_decompressor_chunks_maxsize(self):
lzd = LZMADecompressor()
max_length = 100
@@ -274,6 +289,16 @@ class CompressorDecompressorTestCase(unittest.TestCase):
lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
+ def test_roundtrip_raw_empty(self):
+ lzc = LZMACompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
+ cdata = lzc.compress(INPUT)
+ cdata += lzc.compress(b'')
+ cdata += lzc.compress(b'')
+ cdata += lzc.compress(b'')
+ cdata += lzc.flush()
+ lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
+ self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
+
def test_roundtrip_chunks(self):
lzc = LZMACompressor()
cdata = []
@@ -284,6 +309,19 @@ class CompressorDecompressorTestCase(unittest.TestCase):
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
+ def test_roundtrip_empty_chunks(self):
+ lzc = LZMACompressor()
+ cdata = []
+ for i in range(0, len(INPUT), 10):
+ cdata.append(lzc.compress(INPUT[i:i+10]))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.flush())
+ cdata = b"".join(cdata)
+ lzd = LZMADecompressor()
+ self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
+
# LZMADecompressor intentionally does not handle concatenated streams.
def test_decompressor_multistream(self):