Skip to content

Commit a73fc73

Browse files
authored
bpo-46267: Test compresslevel in gzip.compress (#30416)
Fixes #90425
1 parent e846fe3 commit a73fc73

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_gzip.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,15 @@ def test_compress_mtime(self):
552552
f.read(1) # to set mtime attribute
553553
self.assertEqual(f.mtime, mtime)
554554

555+
def test_compress_correct_level(self):
556+
# gzip.compress calls with mtime == 0 take a different code path.
557+
for mtime in (0, 42):
558+
with self.subTest(mtime=mtime):
559+
nocompress = gzip.compress(data1, compresslevel=0, mtime=mtime)
560+
yescompress = gzip.compress(data1, compresslevel=1, mtime=mtime)
561+
self.assertIn(data1, nocompress)
562+
self.assertNotIn(data1, yescompress)
563+
555564
def test_decompress(self):
556565
for data in (data1, data2):
557566
buf = io.BytesIO()

0 commit comments

Comments
 (0)