summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
authorRuben Vorderman <r.h.p.vorderman@lumc.nl>2024-06-15 18:46:39 (GMT)
committerGitHub <noreply@github.com>2024-06-15 18:46:39 (GMT)
commit08d09cf5ba041c9c5c3860200b56bab66fd44a23 (patch)
tree8366fa5badaf1f9dbeecde4b79922abb06b19e1f /Lib/test/test_gzip.py
parent31d1d72d7e24e0427df70f7dd14b9baff28a4f89 (diff)
downloadcpython-08d09cf5ba041c9c5c3860200b56bab66fd44a23.zip
cpython-08d09cf5ba041c9c5c3860200b56bab66fd44a23.tar.gz
cpython-08d09cf5ba041c9c5c3860200b56bab66fd44a23.tar.bz2
gh-112346: Always set OS byte to 255, simpler gzip.compress function. (GH-120486)
This matches the output behavior in 3.10 and earlier; the optimization in 3.11 allowed the zlib library's "os" value to be filled in instead in the circumstance when mtime was 0. this keeps things consistent.
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r--Lib/test/test_gzip.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index cf80127..ae384c3 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -714,7 +714,6 @@ class TestGzip(BaseTest):
self.assertEqual(f.mtime, mtime)
def test_compress_correct_level(self):
- # gzip.compress calls with mtime == 0 take a different code path.
for mtime in (0, 42):
with self.subTest(mtime=mtime):
nocompress = gzip.compress(data1, compresslevel=0, mtime=mtime)
@@ -722,6 +721,17 @@ class TestGzip(BaseTest):
self.assertIn(data1, nocompress)
self.assertNotIn(data1, yescompress)
+ def test_issue112346(self):
+ # The OS byte should be 255, this should not change between Python versions.
+ for mtime in (0, 42):
+ with self.subTest(mtime=mtime):
+ compress = gzip.compress(data1, compresslevel=1, mtime=mtime)
+ self.assertEqual(
+ struct.unpack("<IxB", compress[4:10]),
+ (mtime, 255),
+ "Gzip header does not properly set either mtime or OS byte."
+ )
+
def test_decompress(self):
for data in (data1, data2):
buf = io.BytesIO()