[Python-checkins] cpython (merge 3.4 -> default): Fixed test_large_file_exception. Ported tests for large count of files

serhiy.storchaka python-checkins at python.org
Tue Sep 23 21:30:20 CEST 2014


https://hg.python.org/cpython/rev/a57351993623
changeset: 92541:a57351993623
parent: 92538:d361d2176121
parent: 92540:c7fd7bf039a8
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Sep 23 22:28:03 2014 +0300
summary:
 Fixed test_large_file_exception. Ported tests for large count of files
to AbstractTestZip64InSmallFiles.
files:
 Lib/test/test_zipfile.py | 63 +++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -462,7 +462,9 @@
 
 def setUp(self):
 self._limit = zipfile.ZIP64_LIMIT
- zipfile.ZIP64_LIMIT = 5
+ self._filecount_limit = zipfile.ZIP_FILECOUNT_LIMIT
+ zipfile.ZIP64_LIMIT = 1000
+ zipfile.ZIP_FILECOUNT_LIMIT = 9
 
 # Make a source file with some lines
 with open(TESTFN, "wb") as fp:
@@ -529,8 +531,67 @@
 for f in get_files(self):
 self.zip_test(f, self.compression)
 
+ def test_too_many_files(self):
+ # This test checks that more than 64k files can be added to an archive,
+ # and that the resulting archive can be read properly by ZipFile
+ zipf = zipfile.ZipFile(TESTFN, "w", self.compression,
+ allowZip64=True)
+ zipf.debug = 100
+ numfiles = 15
+ for i in range(numfiles):
+ zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ zipf.close()
+
+ zipf2 = zipfile.ZipFile(TESTFN, "r", self.compression)
+ self.assertEqual(len(zipf2.namelist()), numfiles)
+ for i in range(numfiles):
+ content = zipf2.read("foo%08d" % i).decode('ascii')
+ self.assertEqual(content, "%d" % (i**3 % 57))
+ zipf2.close()
+
+ def test_too_many_files_append(self):
+ zipf = zipfile.ZipFile(TESTFN, "w", self.compression,
+ allowZip64=False)
+ zipf.debug = 100
+ numfiles = 9
+ for i in range(numfiles):
+ zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ with self.assertRaises(zipfile.LargeZipFile):
+ zipf.writestr("foo%08d" % numfiles, b'')
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ zipf.close()
+
+ zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
+ allowZip64=False)
+ zipf.debug = 100
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ with self.assertRaises(zipfile.LargeZipFile):
+ zipf.writestr("foo%08d" % numfiles, b'')
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ zipf.close()
+
+ zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
+ allowZip64=True)
+ zipf.debug = 100
+ self.assertEqual(len(zipf.namelist()), numfiles)
+ numfiles2 = 15
+ for i in range(numfiles, numfiles2):
+ zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
+ self.assertEqual(len(zipf.namelist()), numfiles2)
+ zipf.close()
+
+ zipf2 = zipfile.ZipFile(TESTFN, "r", self.compression)
+ self.assertEqual(len(zipf2.namelist()), numfiles2)
+ for i in range(numfiles2):
+ content = zipf2.read("foo%08d" % i).decode('ascii')
+ self.assertEqual(content, "%d" % (i**3 % 57))
+ zipf2.close()
+
 def tearDown(self):
 zipfile.ZIP64_LIMIT = self._limit
+ zipfile.ZIP_FILECOUNT_LIMIT = self._filecount_limit
 unlink(TESTFN)
 unlink(TESTFN2)
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /