From 3a052f913b8e607babaf02d9ea668210ef79e836 Mon Sep 17 00:00:00 2001 From: Dustin Lang Date: Fri, 7 Nov 2025 17:25:48 +0000 Subject: [PATCH 1/2] gzip: add tests that an array with items larger than one byte correctly round-trips through GzipFile and gzip.compress -> gzip.decompress --- Lib/test/test_gzip.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 442d30fc970fa9..0b1df96f16f4dc 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -31,6 +31,8 @@ /* See http://www.winimage.com/zLibDll for Windows */ """ +# A single unsigned short - for testing memoryviews with itemsize > 1 +data3 = array.array('H', [1]) TEMPDIR = os.path.abspath(os_helper.TESTFN) + '-gzdir' @@ -101,6 +103,7 @@ def test_write_memoryview(self): m = memoryview(bytes(range(256))) data = m.cast('B', shape=[8,8,4]) self.write_and_read_back(data) + self.write_and_read_back(memoryview(data3)) def test_write_bytearray(self): self.write_and_read_back(bytearray(data1 * 50)) @@ -795,6 +798,16 @@ def test_decompress_missing_trailer(self): compressed_data = gzip.compress(data1) self.assertRaises(EOFError, gzip.decompress, compressed_data[:-8]) + def roundtrip_compress_decompress(self, data): + compressed_data = gzip.compress(data) + decompressed_data = gzip.decompress(compressed_data) + self.assertEqual(decompressed_data, data) + + def test_compress_decompress(self): + self.roundtrip_compress_decompress(data1) + self.roundtrip_compress_decompress(data2) + self.roundtrip_compress_decompress(data3) + def test_read_truncated(self): data = data1*50 # Drop the CRC (4 bytes) and file size (4 bytes). From dff2e60c87c9f6608716a9305322c44384aefdf3 Mon Sep 17 00:00:00 2001 From: Dustin Lang Date: Fri, 7 Nov 2025 17:46:54 +0000 Subject: [PATCH 2/2] oops, actually make new tests pass --- Lib/test/test_gzip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 0b1df96f16f4dc..81d6e4863e0268 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -801,7 +801,7 @@ def test_decompress_missing_trailer(self): def roundtrip_compress_decompress(self, data): compressed_data = gzip.compress(data) decompressed_data = gzip.decompress(compressed_data) - self.assertEqual(decompressed_data, data) + self.assertEqual(decompressed_data, bytes(data)) def test_compress_decompress(self): self.roundtrip_compress_decompress(data1)