Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c399185

Browse files
committed
Issue #9239: add tests for modifying zipfile comments in append mode.
1 parent 4854533 commit c399185

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/test/test_zipfile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,24 @@ def test_comments(self):
972972
with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
973973
self.assertEqual(zipfr.comment, comment2)
974974

975+
# check that comments are correctly modified in append mode
976+
with zipfile.ZipFile(TESTFN,mode="w") as zipf:
977+
zipf.comment = b"original comment"
978+
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
979+
with zipfile.ZipFile(TESTFN,mode="a") as zipf:
980+
zipf.comment = b"an updated comment"
981+
with zipfile.ZipFile(TESTFN,mode="r") as zipf:
982+
self.assertEqual(zipf.comment, b"an updated comment")
983+
984+
# check that comments are correctly shortened in append mode
985+
with zipfile.ZipFile(TESTFN,mode="w") as zipf:
986+
zipf.comment = b"original comment that's longer"
987+
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
988+
with zipfile.ZipFile(TESTFN,mode="a") as zipf:
989+
zipf.comment = b"shorter comment"
990+
with zipfile.ZipFile(TESTFN,mode="r") as zipf:
991+
self.assertEqual(zipf.comment, b"shorter comment")
992+
975993
def test_unicode_comment(self):
976994
with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
977995
zipf.writestr("foo.txt", "O, for a Muse of Fire!")

0 commit comments

Comments
 (0)