[Python-checkins] bpo-46267: Test compresslevel in gzip.compress (#30416)

JelleZijlstra webhook-mailer at python.org
Tue May 3 01:11:10 EDT 2022


https://github.com/python/cpython/commit/a73fc73ff7586b09d68a330760d06862f5bafb9b
commit: a73fc73ff7586b09d68a330760d06862f5bafb9b
branch: main
author: Ruben Vorderman <r.h.p.vorderman at lumc.nl>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-05-02T23:11:06-06:00
summary:

bpo-46267: Test compresslevel in gzip.compress  (#30416)

Fixes #90425

files:
M Lib/test/test_gzip.py

diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 497e66cd553b7..6de413e5056ef 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -552,6 +552,15 @@ def test_compress_mtime(self):
                         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()



More information about the Python-checkins mailing list