summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
authorguoci <zguoci@gmail.com>2018-11-07 09:50:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-11-07 09:50:23 (GMT)
commit0e7497cb469b003a45a4abe4105b81ef6d0c4002 (patch)
tree6c14770bf03a79d5e2ce008432309cfbddab858e /Lib/test/test_gzip.py
parentd2b11af91560eaaeb499f702f4b0f244ec756280 (diff)
downloadcpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.zip
cpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.tar.gz
cpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.tar.bz2
bpo-34898: Add mtime parameter to gzip.compress(). (GH-9704)
Without setting mtime, time.time() will be used as the timestamp which will end up in the compressed data and each invocation of the compress() function will vary over time.
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r--Lib/test/test_gzip.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 1e8b41f..2c8f854 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -499,6 +499,17 @@ class TestGzip(BaseTest):
with gzip.GzipFile(fileobj=io.BytesIO(datac), mode="rb") as f:
self.assertEqual(f.read(), data)
+ def test_compress_mtime(self):
+ mtime = 123456789
+ for data in [data1, data2]:
+ for args in [(), (1,), (6,), (9,)]:
+ with self.subTest(data=data, args=args):
+ datac = gzip.compress(data, *args, mtime=mtime)
+ self.assertEqual(type(datac), bytes)
+ with gzip.GzipFile(fileobj=io.BytesIO(datac), mode="rb") as f:
+ f.read(1) # to set mtime attribute
+ self.assertEqual(f.mtime, mtime)
+
def test_decompress(self):
for data in (data1, data2):
buf = io.BytesIO()