diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-30 15:31:37 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-30 15:31:37 (GMT) |
commit | c399185fcc9ca795840db4c94f273effa2d40947 (patch) | |
tree | ce2824f0bc58db728689ff68bdf5c46cba435bf5 /Lib/test | |
parent | 4854533f6d738b7a21726b80e144040510526440 (diff) | |
download | cpython-c399185fcc9ca795840db4c94f273effa2d40947.zip cpython-c399185fcc9ca795840db4c94f273effa2d40947.tar.gz cpython-c399185fcc9ca795840db4c94f273effa2d40947.tar.bz2 |
Issue #9239: add tests for modifying zipfile comments in append mode.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipfile.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index c0675c6..51d8b45 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -972,6 +972,24 @@ class OtherTests(unittest.TestCase): with zipfile.ZipFile(TESTFN, mode="r") as zipfr: self.assertEqual(zipfr.comment, comment2) + # check that comments are correctly modified in append mode + with zipfile.ZipFile(TESTFN,mode="w") as zipf: + zipf.comment = b"original comment" + zipf.writestr("foo.txt", "O, for a Muse of Fire!") + with zipfile.ZipFile(TESTFN,mode="a") as zipf: + zipf.comment = b"an updated comment" + with zipfile.ZipFile(TESTFN,mode="r") as zipf: + self.assertEqual(zipf.comment, b"an updated comment") + + # check that comments are correctly shortened in append mode + 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!") + with zipfile.ZipFile(TESTFN,mode="a") as zipf: + zipf.comment = b"shorter comment" + with zipfile.ZipFile(TESTFN,mode="r") as zipf: + self.assertEqual(zipf.comment, b"shorter comment") + def test_unicode_comment(self): with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") |