summaryrefslogtreecommitdiff
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-07-03 12:51:14 +0000
committerMartin v. Löwis <martin@v.loewis.de>2008-07-03 12:51:14 +0000
commit8c4364127193100d0c3e267f5a49aadd096732a6 (patch)
treef7e0f461e58fa5cd6d923b9d09e4010aa767bc8b /Lib/test/test_zipfile.py
parentf5d2b4ce930666c9f58c9c7da1744388143860df (diff)
downloadcpython-git-8c4364127193100d0c3e267f5a49aadd096732a6.tar.gz
Patch #1622: Correct interpretation of various ZIP header fields.
Also fixes - Issue #1526: Allow more than 64k files to be added to Zip64 file. - Issue #1746: Correct handling of zipfile archive comments (previously archives with comments over 4k were flagged as invalid). Allow writing Zip files with archives by setting the 'comment' attribute of a ZipFile.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 4bc2104d1b..90ac4f6f6e 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -712,6 +712,54 @@ class OtherTests(unittest.TestCase):
zipf.writestr("foo.txt\x00qqq", "O, for a Muse of Fire!")
self.assertEqual(zipf.namelist(), ['foo.txt'])
+ def test_StructSizes(self):
+ # check that ZIP internal structure sizes are calculated correctly
+ self.assertEqual(zipfile.sizeEndCentDir, 22)
+ self.assertEqual(zipfile.sizeCentralDir, 46)
+ self.assertEqual(zipfile.sizeEndCentDir64, 56)
+ self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
+
+ def testComments(self):
+ # This test checks that comments on the archive are handled properly
+
+ # check default comment is empty
+ zipf = zipfile.ZipFile(TESTFN, mode="w")
+ self.assertEqual(zipf.comment, '')
+ zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ zipf.close()
+ zipfr = zipfile.ZipFile(TESTFN, mode="r")
+ self.assertEqual(zipfr.comment, '')
+ zipfr.close()
+
+ # check a simple short comment
+ comment = 'Bravely taking to his feet, he beat a very brave retreat.'
+ zipf = zipfile.ZipFile(TESTFN, mode="w")
+ zipf.comment = comment
+ zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ zipf.close()
+ zipfr = zipfile.ZipFile(TESTFN, mode="r")
+ self.assertEqual(zipfr.comment, comment)
+ zipfr.close()
+
+ # check a comment of max length
+ comment2 = ''.join(['%d' % (i**3 % 10) for i in xrange((1 << 16)-1)])
+ zipf = zipfile.ZipFile(TESTFN, mode="w")
+ zipf.comment = comment2
+ zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ zipf.close()
+ zipfr = zipfile.ZipFile(TESTFN, mode="r")
+ self.assertEqual(zipfr.comment, comment2)
+ zipfr.close()
+
+ # check a comment that is too long is truncated
+ zipf = zipfile.ZipFile(TESTFN, mode="w")
+ zipf.comment = comment2 + 'oops'
+ zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ zipf.close()
+ zipfr = zipfile.ZipFile(TESTFN, mode="r")
+ self.assertEqual(zipfr.comment, comment2)
+ zipfr.close()
+
def tearDown(self):
support.unlink(TESTFN)
support.unlink(TESTFN2)