@@ -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