blob: c9807bfd799172b8bda68830b2364642e3959cc7 [file] [log] [blame]
Ronald Oussoren143cefb2006-06-15 08:14:18 +00001# Tests of the full ZIP64 functionality of zipfile
2# The test_support.requires call is the only reason for keeping this separate
3# from test_zipfile
4from test import test_support
5test_support.requires(
6 'largefile',
7 'test requires loads of disk-space bytes and a long time to run'
8 )
9
10# We can test part of the module without zlib.
11try:
12 import zlib
13except ImportError:
14 zlib = None
15
16import zipfile, os, unittest
17
18from StringIO import StringIO
19from tempfile import TemporaryFile
20
21from test.test_support import TESTFN, run_unittest
22
23TESTFN2 = TESTFN + "2"
24
25class TestsWithSourceFile(unittest.TestCase):
26 def setUp(self):
27 line_gen = ("Test of zipfile line %d." % i for i in range(0, 1000000))
28 self.data = '\n'.join(line_gen)
29
30 # Make a source file with some lines
31 fp = open(TESTFN, "wb")
32 fp.write(self.data)
33 fp.close()
34
35 def zipTest(self, f, compression):
36 # Create the ZIP archive
37 filecount = int(((1 << 32) / len(self.data)) * 1.5)
38 zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True)
39
40 for num in range(filecount):
41 zipfp.writestr("testfn%d"%(num,), self.data)
42 zipfp.close()
43
44 # Read the ZIP archive
45 zipfp = zipfile.ZipFile(f, "r", compression)
46 for num in range(filecount):
47 self.assertEqual(zipfp.read("testfn%d"%(num,)), self.data)
48 zipfp.close()
49
50 def testStored(self):
51 for f in (TESTFN2, TemporaryFile()):
52 self.zipTest(f, zipfile.ZIP_STORED)
53
54 if zlib:
55 def testDeflated(self):
56 for f in (TESTFN2, TemporaryFile()):
57 self.zipTest(f, zipfile.ZIP_DEFLATED)
58
59 def tearDown(self):
60 os.remove(TESTFN)
61 os.remove(TESTFN2)
62
63def test_main():
64 run_unittest(TestsWithSourceFile)
65
66if __name__ == "__main__":
67 test_main()