Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check whether file whether zipfile was truncated when appending short…
…er comment
  • Loading branch information
mzr committed Sep 28, 2020
commit a93382e8d62e9b3ac1a17f2e3723762e42c5c7ab
10 changes: 4 additions & 6 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,17 +1853,15 @@ def test_comments(self):

# check that comments are correctly shortened in append mode
# and the file is indeed truncated
original_comment = b"original comment that's longer"
one_byte_shorter_comment = original_comment[:-1]
with zipfile.ZipFile(TESTFN,mode="w") as zipf:
zipf.comment = original_comment
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 = one_byte_shorter_comment
self.assertEqual(original_zip_size, os.path.getsize(TESTFN) + 1)
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, one_byte_shorter_comment)
self.assertEqual(zipf.comment, b"shorter comment")

def test_unicode_comment(self):
with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
Expand Down