Skip to content

Commit 3a052f9

Browse files
committed
gzip: add tests that an array with items larger than one byte correctly round-trips through GzipFile and gzip.compress -> gzip.decompress
1 parent 7af9b53 commit 3a052f9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/test/test_gzip.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
/* See http://www.winimage.com/zLibDll for Windows */
3232
"""
3333

34+
# A single unsigned short - for testing memoryviews with itemsize > 1
35+
data3 = array.array('H', [1])
3436

3537
TEMPDIR = os.path.abspath(os_helper.TESTFN) + '-gzdir'
3638

@@ -101,6 +103,7 @@ def test_write_memoryview(self):
101103
m = memoryview(bytes(range(256)))
102104
data = m.cast('B', shape=[8,8,4])
103105
self.write_and_read_back(data)
106+
self.write_and_read_back(memoryview(data3))
104107

105108
def test_write_bytearray(self):
106109
self.write_and_read_back(bytearray(data1 * 50))
@@ -795,6 +798,16 @@ def test_decompress_missing_trailer(self):
795798
compressed_data = gzip.compress(data1)
796799
self.assertRaises(EOFError, gzip.decompress, compressed_data[:-8])
797800

801+
def roundtrip_compress_decompress(self, data):
802+
compressed_data = gzip.compress(data)
803+
decompressed_data = gzip.decompress(compressed_data)
804+
self.assertEqual(decompressed_data, data)
805+
806+
def test_compress_decompress(self):
807+
self.roundtrip_compress_decompress(data1)
808+
self.roundtrip_compress_decompress(data2)
809+
self.roundtrip_compress_decompress(data3)
810+
798811
def test_read_truncated(self):
799812
data = data1*50
800813
# Drop the CRC (4 bytes) and file size (4 bytes).

0 commit comments

Comments
 (0)