summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-28 19:18:39 (GMT)
committerGitHub <noreply@github.com>2020-09-28 19:18:39 (GMT)
commite4008404fbc0002c49becc565d42e93eca11dd75 (patch)
tree61743ef7423eaa0070c1207e9e3233a19ee6c113 /Lib/test
parente0e614ca99c39e107b97c7be779efea08f22ace3 (diff)
downloadcpython-e4008404fbc0002c49becc565d42e93eca11dd75.zip
cpython-e4008404fbc0002c49becc565d42e93eca11dd75.tar.gz
cpython-e4008404fbc0002c49becc565d42e93eca11dd75.tar.bz2
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
(cherry picked from commit ff9147d93b868f0e13b9fe14e2a76c2879f6787b) Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_zipfile.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index e2e37a1..3115344 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1844,11 +1844,14 @@ class OtherTests(unittest.TestCase):
self.assertEqual(zipf.comment, b"an updated comment")
# check that comments are correctly shortened in append mode
+ # and the file is indeed truncated
with zipfile.ZipFile(TESTFN,mode="w") as zipf:
zipf.comment = b"original comment that's longer"
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ original_zip_size = os.path.getsize(TESTFN)
with zipfile.ZipFile(TESTFN,mode="a") as zipf:
zipf.comment = b"shorter comment"
+ self.assertTrue(original_zip_size > os.path.getsize(TESTFN))
with zipfile.ZipFile(TESTFN,mode="r") as zipf:
self.assertEqual(zipf.comment, b"shorter comment")