]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46267: Test compresslevel in gzip.compress (#30416)
authorRuben Vorderman <r.h.p.vorderman@lumc.nl>
Tue, 3 May 2022 05:11:06 +0000 (07:11 +0200)
committerGitHub <noreply@github.com>
Tue, 3 May 2022 05:11:06 +0000 (23:11 -0600)
Fixes #90425

Lib/test/test_gzip.py

index 497e66cd553b7f042d449747bc901c2f97459b66..6de413e5056ef0ea444f0488d866f26858f52047 100644 (file)
@@ -552,6 +552,15 @@ class TestGzip(BaseTest):
                         f.read(1) # to set mtime attribute
                         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)
+                yescompress = gzip.compress(data1, compresslevel=1, mtime=mtime)
+                self.assertIn(data1, nocompress)
+                self.assertNotIn(data1, yescompress)
+
     def test_decompress(self):
         for data in (data1, data2):
             buf = io.BytesIO()