blob: 40003aa2f0c8014ccc0843b64d48a2830064936c [file] [log] [blame]
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +00001# We can test part of the module without zlib.
Guido van Rossum368f04a2000-04-10 13:23:04 +00002try:
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +00003 import zlib
4except ImportError:
5 zlib = None
Tim Petersa45cacf2004-08-20 03:47:14 +00006
Martin v. Löwis3eb76482007-03-06 10:41:24 +00007import zipfile, os, unittest, sys, shutil, struct
Tim Petersa19a1682001-03-29 04:36:09 +00008
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +00009from StringIO import StringIO
10from tempfile import TemporaryFile
Martin v. Löwis3eb76482007-03-06 10:41:24 +000011from random import randint, random
Tim Petersa19a1682001-03-29 04:36:09 +000012
Collin Winter04a51ec2007-03-29 02:28:16 +000013import test.test_support as support
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000014from test.test_support import TESTFN, run_unittest
Guido van Rossum368f04a2000-04-10 13:23:04 +000015
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000016TESTFN2 = TESTFN + "2"
Georg Brandl4b3ab6f2007-07-12 09:59:22 +000017FIXEDTEST_SIZE = 1000
Guido van Rossum368f04a2000-04-10 13:23:04 +000018
Georg Brandl62416bc2008-01-07 18:47:44 +000019SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
20 ('ziptest2dir/_ziptest2', 'qawsedrftg'),
21 ('/ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'),
22 ('ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3', '6y7u8i9o0p')]
23
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000024class TestsWithSourceFile(unittest.TestCase):
25 def setUp(self):
Georg Brandl4b3ab6f2007-07-12 09:59:22 +000026 self.line_gen = ["Zipfile test line %d. random float: %f" % (i, random())
27 for i in xrange(FIXEDTEST_SIZE)]
Martin v. Löwis3eb76482007-03-06 10:41:24 +000028 self.data = '\n'.join(self.line_gen) + '\n'
Fred Drake6e7e4852001-02-28 05:34:16 +000029
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000030 # Make a source file with some lines
31 fp = open(TESTFN, "wb")
32 fp.write(self.data)
33 fp.close()
Tim Peters7d3bad62001-04-04 18:56:49 +000034
Martin v. Löwis3eb76482007-03-06 10:41:24 +000035 def makeTestArchive(self, f, compression):
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000036 # Create the ZIP archive
37 zipfp = zipfile.ZipFile(f, "w", compression)
38 zipfp.write(TESTFN, "another"+os.extsep+"name")
39 zipfp.write(TESTFN, TESTFN)
Ronald Oussoren143cefb2006-06-15 08:14:18 +000040 zipfp.writestr("strfile", self.data)
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000041 zipfp.close()
Tim Peters7d3bad62001-04-04 18:56:49 +000042
Martin v. Löwis3eb76482007-03-06 10:41:24 +000043 def zipTest(self, f, compression):
44 self.makeTestArchive(f, compression)
45
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +000046 # Read the ZIP archive
47 zipfp = zipfile.ZipFile(f, "r", compression)
48 self.assertEqual(zipfp.read(TESTFN), self.data)
49 self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
Ronald Oussoren143cefb2006-06-15 08:14:18 +000050 self.assertEqual(zipfp.read("strfile"), self.data)
51
52 # Print the ZIP directory
53 fp = StringIO()
54 stdout = sys.stdout
55 try:
56 sys.stdout = fp
57
58 zipfp.printdir()
59 finally:
60 sys.stdout = stdout
Tim Petersa608bb22006-06-15 18:06:29 +000061
Ronald Oussoren143cefb2006-06-15 08:14:18 +000062 directory = fp.getvalue()
63 lines = directory.splitlines()
64 self.assertEquals(len(lines), 4) # Number of files + header
65
66 self.assert_('File Name' in lines[0])
67 self.assert_('Modified' in lines[0])
68 self.assert_('Size' in lines[0])
69
70 fn, date, time, size = lines[1].split()
71 self.assertEquals(fn, 'another.name')
72 # XXX: timestamp is not tested
73 self.assertEquals(size, str(len(self.data)))
74
75 # Check the namelist
76 names = zipfp.namelist()
77 self.assertEquals(len(names), 3)
78 self.assert_(TESTFN in names)
79 self.assert_("another"+os.extsep+"name" in names)
80 self.assert_("strfile" in names)
81
82 # Check infolist
83 infos = zipfp.infolist()
84 names = [ i.filename for i in infos ]
85 self.assertEquals(len(names), 3)
86 self.assert_(TESTFN in names)
87 self.assert_("another"+os.extsep+"name" in names)
88 self.assert_("strfile" in names)
89 for i in infos:
90 self.assertEquals(i.file_size, len(self.data))
91
92 # check getinfo
93 for nm in (TESTFN, "another"+os.extsep+"name", "strfile"):
94 info = zipfp.getinfo(nm)
95 self.assertEquals(info.filename, nm)
96 self.assertEquals(info.file_size, len(self.data))
97
98 # Check that testzip doesn't raise an exception
99 zipfp.testzip()
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000100 zipfp.close()
Tim Peters7d3bad62001-04-04 18:56:49 +0000101
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000102 def testStored(self):
103 for f in (TESTFN2, TemporaryFile(), StringIO()):
104 self.zipTest(f, zipfile.ZIP_STORED)
Raymond Hettingerc0fac962003-06-27 22:25:03 +0000105
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000106 def zipOpenTest(self, f, compression):
107 self.makeTestArchive(f, compression)
108
109 # Read the ZIP archive
110 zipfp = zipfile.ZipFile(f, "r", compression)
111 zipdata1 = []
112 zipopen1 = zipfp.open(TESTFN)
113 while 1:
114 read_data = zipopen1.read(256)
115 if not read_data:
116 break
117 zipdata1.append(read_data)
118
119 zipdata2 = []
120 zipopen2 = zipfp.open("another"+os.extsep+"name")
121 while 1:
122 read_data = zipopen2.read(256)
123 if not read_data:
124 break
125 zipdata2.append(read_data)
Tim Petersea5962f2007-03-12 18:07:52 +0000126
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000127 self.assertEqual(''.join(zipdata1), self.data)
128 self.assertEqual(''.join(zipdata2), self.data)
129 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000130
131 def testOpenStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000132 for f in (TESTFN2, TemporaryFile(), StringIO()):
133 self.zipOpenTest(f, zipfile.ZIP_STORED)
134
135 def zipRandomOpenTest(self, f, compression):
136 self.makeTestArchive(f, compression)
137
138 # Read the ZIP archive
139 zipfp = zipfile.ZipFile(f, "r", compression)
140 zipdata1 = []
141 zipopen1 = zipfp.open(TESTFN)
142 while 1:
143 read_data = zipopen1.read(randint(1, 1024))
144 if not read_data:
145 break
146 zipdata1.append(read_data)
147
148 self.assertEqual(''.join(zipdata1), self.data)
149 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000150
151 def testRandomOpenStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000152 for f in (TESTFN2, TemporaryFile(), StringIO()):
153 self.zipRandomOpenTest(f, zipfile.ZIP_STORED)
Tim Petersea5962f2007-03-12 18:07:52 +0000154
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000155 def zipReadlineTest(self, f, compression):
156 self.makeTestArchive(f, compression)
157
158 # Read the ZIP archive
159 zipfp = zipfile.ZipFile(f, "r")
160 zipopen = zipfp.open(TESTFN)
161 for line in self.line_gen:
162 linedata = zipopen.readline()
163 self.assertEqual(linedata, line + '\n')
164
165 zipfp.close()
166
167 def zipReadlinesTest(self, f, compression):
168 self.makeTestArchive(f, compression)
169
170 # Read the ZIP archive
171 zipfp = zipfile.ZipFile(f, "r")
172 ziplines = zipfp.open(TESTFN).readlines()
173 for line, zipline in zip(self.line_gen, ziplines):
174 self.assertEqual(zipline, line + '\n')
175
176 zipfp.close()
177
178 def zipIterlinesTest(self, f, compression):
179 self.makeTestArchive(f, compression)
180
181 # Read the ZIP archive
182 zipfp = zipfile.ZipFile(f, "r")
183 for line, zipline in zip(self.line_gen, zipfp.open(TESTFN)):
184 self.assertEqual(zipline, line + '\n')
185
186 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000187
188 def testReadlineStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000189 for f in (TESTFN2, TemporaryFile(), StringIO()):
190 self.zipReadlineTest(f, zipfile.ZIP_STORED)
191
Tim Petersea5962f2007-03-12 18:07:52 +0000192 def testReadlinesStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000193 for f in (TESTFN2, TemporaryFile(), StringIO()):
194 self.zipReadlinesTest(f, zipfile.ZIP_STORED)
195
Tim Petersea5962f2007-03-12 18:07:52 +0000196 def testIterlinesStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000197 for f in (TESTFN2, TemporaryFile(), StringIO()):
198 self.zipIterlinesTest(f, zipfile.ZIP_STORED)
199
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000200 if zlib:
201 def testDeflated(self):
202 for f in (TESTFN2, TemporaryFile(), StringIO()):
203 self.zipTest(f, zipfile.ZIP_DEFLATED)
Raymond Hettingerc0fac962003-06-27 22:25:03 +0000204
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000205 def testOpenDeflated(self):
206 for f in (TESTFN2, TemporaryFile(), StringIO()):
207 self.zipOpenTest(f, zipfile.ZIP_DEFLATED)
208
209 def testRandomOpenDeflated(self):
210 for f in (TESTFN2, TemporaryFile(), StringIO()):
211 self.zipRandomOpenTest(f, zipfile.ZIP_DEFLATED)
212
Tim Petersea5962f2007-03-12 18:07:52 +0000213 def testReadlineDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000214 for f in (TESTFN2, TemporaryFile(), StringIO()):
215 self.zipReadlineTest(f, zipfile.ZIP_DEFLATED)
216
Tim Petersea5962f2007-03-12 18:07:52 +0000217 def testReadlinesDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000218 for f in (TESTFN2, TemporaryFile(), StringIO()):
219 self.zipReadlinesTest(f, zipfile.ZIP_DEFLATED)
220
Tim Petersea5962f2007-03-12 18:07:52 +0000221 def testIterlinesDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000222 for f in (TESTFN2, TemporaryFile(), StringIO()):
223 self.zipIterlinesTest(f, zipfile.ZIP_DEFLATED)
Tim Petersea5962f2007-03-12 18:07:52 +0000224
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000225 def testLowCompression(self):
226 # Checks for cases where compressed data is larger than original
227 # Create the ZIP archive
228 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
229 zipfp.writestr("strfile", '12')
230 zipfp.close()
231
232 # Get an open object for strfile
233 zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED)
234 openobj = zipfp.open("strfile")
235 self.assertEqual(openobj.read(1), '1')
236 self.assertEqual(openobj.read(1), '2')
237
Georg Brandl8f7c54e2006-02-20 08:40:38 +0000238 def testAbsoluteArcnames(self):
239 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
240 zipfp.write(TESTFN, "/absolute")
241 zipfp.close()
242
243 zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED)
244 self.assertEqual(zipfp.namelist(), ["absolute"])
245 zipfp.close()
Tim Peters32cbc962006-02-20 21:42:18 +0000246
Georg Brandl4b3ab6f2007-07-12 09:59:22 +0000247 def testAppendToZipFile(self):
248 # Test appending to an existing zipfile
249 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
250 zipfp.write(TESTFN, TESTFN)
251 zipfp.close()
252 zipfp = zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED)
253 zipfp.writestr("strfile", self.data)
254 self.assertEqual(zipfp.namelist(), [TESTFN, "strfile"])
255 zipfp.close()
256
257 def testAppendToNonZipFile(self):
258 # Test appending to an existing file that is not a zipfile
259 # NOTE: this test fails if len(d) < 22 because of the first
260 # line "fpin.seek(-22, 2)" in _EndRecData
261 d = 'I am not a ZipFile!'*10
262 f = file(TESTFN2, 'wb')
263 f.write(d)
264 f.close()
265 zipfp = zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED)
266 zipfp.write(TESTFN, TESTFN)
267 zipfp.close()
268
269 f = file(TESTFN2, 'rb')
270 f.seek(len(d))
271 zipfp = zipfile.ZipFile(f, "r")
272 self.assertEqual(zipfp.namelist(), [TESTFN])
273 zipfp.close()
274 f.close()
275
276 def test_WriteDefaultName(self):
277 # Check that calling ZipFile.write without arcname specified produces the expected result
278 zipfp = zipfile.ZipFile(TESTFN2, "w")
279 zipfp.write(TESTFN)
280 self.assertEqual(zipfp.read(TESTFN), file(TESTFN).read())
281 zipfp.close()
282
283 def test_PerFileCompression(self):
284 # Check that files within a Zip archive can have different compression options
285 zipfp = zipfile.ZipFile(TESTFN2, "w")
286 zipfp.write(TESTFN, 'storeme', zipfile.ZIP_STORED)
287 zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
288 sinfo = zipfp.getinfo('storeme')
289 dinfo = zipfp.getinfo('deflateme')
290 self.assertEqual(sinfo.compress_type, zipfile.ZIP_STORED)
291 self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED)
292 zipfp.close()
293
294 def test_WriteToReadonly(self):
295 # Check that trying to call write() on a readonly ZipFile object
296 # raises a RuntimeError
297 zipf = zipfile.ZipFile(TESTFN2, mode="w")
298 zipf.writestr("somefile.txt", "bogus")
299 zipf.close()
300 zipf = zipfile.ZipFile(TESTFN2, mode="r")
301 self.assertRaises(RuntimeError, zipf.write, TESTFN)
302 zipf.close()
303
Georg Brandl62416bc2008-01-07 18:47:44 +0000304 def testExtract(self):
305 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
306 for fpath, fdata in SMALL_TEST_DATA:
307 zipfp.writestr(fpath, fdata)
308 zipfp.close()
309
310 zipfp = zipfile.ZipFile(TESTFN2, "r")
311 for fpath, fdata in SMALL_TEST_DATA:
312 writtenfile = zipfp.extract(fpath)
313
314 # make sure it was written to the right place
315 if os.path.isabs(fpath):
316 correctfile = os.path.join(os.getcwd(), fpath[1:])
317 else:
318 correctfile = os.path.join(os.getcwd(), fpath)
319
320 self.assertEqual(writtenfile, correctfile)
321
322 # make sure correct data is in correct file
323 self.assertEqual(fdata, file(writtenfile, "rb").read())
324
325 os.remove(writtenfile)
326
327 zipfp.close()
328
329 # remove the test file subdirectories
330 shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
331
332 def testExtractAll(self):
333 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
334 for fpath, fdata in SMALL_TEST_DATA:
335 zipfp.writestr(fpath, fdata)
336 zipfp.close()
337
338 zipfp = zipfile.ZipFile(TESTFN2, "r")
339 zipfp.extractall()
340 for fpath, fdata in SMALL_TEST_DATA:
341 if os.path.isabs(fpath):
342 outfile = os.path.join(os.getcwd(), fpath[1:])
343 else:
344 outfile = os.path.join(os.getcwd(), fpath)
345
346 self.assertEqual(fdata, file(outfile, "rb").read())
347
348 os.remove(outfile)
349
350 zipfp.close()
351
352 # remove the test file subdirectories
353 shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
354
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000355 def tearDown(self):
356 os.remove(TESTFN)
357 os.remove(TESTFN2)
358
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000359class TestZip64InSmallFiles(unittest.TestCase):
360 # These tests test the ZIP64 functionality without using large files,
361 # see test_zipfile64 for proper tests.
362
363 def setUp(self):
364 self._limit = zipfile.ZIP64_LIMIT
365 zipfile.ZIP64_LIMIT = 5
366
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000367 line_gen = ("Test of zipfile line %d." % i for i in range(0, FIXEDTEST_SIZE))
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000368 self.data = '\n'.join(line_gen)
369
370 # Make a source file with some lines
371 fp = open(TESTFN, "wb")
372 fp.write(self.data)
373 fp.close()
374
375 def largeFileExceptionTest(self, f, compression):
376 zipfp = zipfile.ZipFile(f, "w", compression)
Tim Petersa608bb22006-06-15 18:06:29 +0000377 self.assertRaises(zipfile.LargeZipFile,
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000378 zipfp.write, TESTFN, "another"+os.extsep+"name")
379 zipfp.close()
380
381 def largeFileExceptionTest2(self, f, compression):
382 zipfp = zipfile.ZipFile(f, "w", compression)
Tim Petersa608bb22006-06-15 18:06:29 +0000383 self.assertRaises(zipfile.LargeZipFile,
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000384 zipfp.writestr, "another"+os.extsep+"name", self.data)
385 zipfp.close()
386
387 def testLargeFileException(self):
388 for f in (TESTFN2, TemporaryFile(), StringIO()):
389 self.largeFileExceptionTest(f, zipfile.ZIP_STORED)
390 self.largeFileExceptionTest2(f, zipfile.ZIP_STORED)
391
392 def zipTest(self, f, compression):
393 # Create the ZIP archive
394 zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True)
395 zipfp.write(TESTFN, "another"+os.extsep+"name")
396 zipfp.write(TESTFN, TESTFN)
397 zipfp.writestr("strfile", self.data)
398 zipfp.close()
399
400 # Read the ZIP archive
401 zipfp = zipfile.ZipFile(f, "r", compression)
402 self.assertEqual(zipfp.read(TESTFN), self.data)
403 self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
404 self.assertEqual(zipfp.read("strfile"), self.data)
405
406 # Print the ZIP directory
407 fp = StringIO()
408 stdout = sys.stdout
409 try:
410 sys.stdout = fp
411
412 zipfp.printdir()
413 finally:
414 sys.stdout = stdout
Tim Petersa608bb22006-06-15 18:06:29 +0000415
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000416 directory = fp.getvalue()
417 lines = directory.splitlines()
418 self.assertEquals(len(lines), 4) # Number of files + header
419
420 self.assert_('File Name' in lines[0])
421 self.assert_('Modified' in lines[0])
422 self.assert_('Size' in lines[0])
423
424 fn, date, time, size = lines[1].split()
425 self.assertEquals(fn, 'another.name')
426 # XXX: timestamp is not tested
427 self.assertEquals(size, str(len(self.data)))
428
429 # Check the namelist
430 names = zipfp.namelist()
431 self.assertEquals(len(names), 3)
432 self.assert_(TESTFN in names)
433 self.assert_("another"+os.extsep+"name" in names)
434 self.assert_("strfile" in names)
435
436 # Check infolist
437 infos = zipfp.infolist()
438 names = [ i.filename for i in infos ]
439 self.assertEquals(len(names), 3)
440 self.assert_(TESTFN in names)
441 self.assert_("another"+os.extsep+"name" in names)
442 self.assert_("strfile" in names)
443 for i in infos:
444 self.assertEquals(i.file_size, len(self.data))
445
446 # check getinfo
447 for nm in (TESTFN, "another"+os.extsep+"name", "strfile"):
448 info = zipfp.getinfo(nm)
449 self.assertEquals(info.filename, nm)
450 self.assertEquals(info.file_size, len(self.data))
451
452 # Check that testzip doesn't raise an exception
453 zipfp.testzip()
454
455
456 zipfp.close()
457
458 def testStored(self):
459 for f in (TESTFN2, TemporaryFile(), StringIO()):
460 self.zipTest(f, zipfile.ZIP_STORED)
461
462
463 if zlib:
464 def testDeflated(self):
465 for f in (TESTFN2, TemporaryFile(), StringIO()):
466 self.zipTest(f, zipfile.ZIP_DEFLATED)
467
468 def testAbsoluteArcnames(self):
469 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True)
470 zipfp.write(TESTFN, "/absolute")
471 zipfp.close()
472
473 zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED)
474 self.assertEqual(zipfp.namelist(), ["absolute"])
475 zipfp.close()
476
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000477 def tearDown(self):
478 zipfile.ZIP64_LIMIT = self._limit
479 os.remove(TESTFN)
480 os.remove(TESTFN2)
481
482class PyZipFileTests(unittest.TestCase):
483 def testWritePyfile(self):
484 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
485 fn = __file__
486 if fn.endswith('.pyc') or fn.endswith('.pyo'):
487 fn = fn[:-1]
488
489 zipfp.writepy(fn)
490
491 bn = os.path.basename(fn)
492 self.assert_(bn not in zipfp.namelist())
493 self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist())
494 zipfp.close()
495
496
497 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
498 fn = __file__
499 if fn.endswith('.pyc') or fn.endswith('.pyo'):
500 fn = fn[:-1]
501
502 zipfp.writepy(fn, "testpackage")
503
504 bn = "%s/%s"%("testpackage", os.path.basename(fn))
505 self.assert_(bn not in zipfp.namelist())
506 self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist())
507 zipfp.close()
508
509 def testWritePythonPackage(self):
510 import email
511 packagedir = os.path.dirname(email.__file__)
512
513 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
514 zipfp.writepy(packagedir)
515
516 # Check for a couple of modules at different levels of the hieararchy
517 names = zipfp.namelist()
518 self.assert_('email/__init__.pyo' in names or 'email/__init__.pyc' in names)
519 self.assert_('email/mime/text.pyo' in names or 'email/mime/text.pyc' in names)
520
521 def testWritePythonDirectory(self):
522 os.mkdir(TESTFN2)
523 try:
524 fp = open(os.path.join(TESTFN2, "mod1.py"), "w")
525 fp.write("print 42\n")
526 fp.close()
527
528 fp = open(os.path.join(TESTFN2, "mod2.py"), "w")
529 fp.write("print 42 * 42\n")
530 fp.close()
531
532 fp = open(os.path.join(TESTFN2, "mod2.txt"), "w")
533 fp.write("bla bla bla\n")
534 fp.close()
535
536 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
537 zipfp.writepy(TESTFN2)
538
539 names = zipfp.namelist()
540 self.assert_('mod1.pyc' in names or 'mod1.pyo' in names)
541 self.assert_('mod2.pyc' in names or 'mod2.pyo' in names)
542 self.assert_('mod2.txt' not in names)
543
544 finally:
545 shutil.rmtree(TESTFN2)
546
Georg Brandl4b3ab6f2007-07-12 09:59:22 +0000547 def testWriteNonPyfile(self):
548 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
549 file(TESTFN, 'w').write('most definitely not a python file')
550 self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
551 os.remove(TESTFN)
Ronald Oussoren143cefb2006-06-15 08:14:18 +0000552
553
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000554class OtherTests(unittest.TestCase):
Martin v. Löwis84f6de92007-02-13 10:10:39 +0000555 def testCreateNonExistentFileForAppend(self):
556 if os.path.exists(TESTFN):
557 os.unlink(TESTFN)
Tim Petersea5962f2007-03-12 18:07:52 +0000558
Martin v. Löwis84f6de92007-02-13 10:10:39 +0000559 filename = 'testfile.txt'
560 content = 'hello, world. this is some content.'
Tim Petersea5962f2007-03-12 18:07:52 +0000561
Martin v. Löwis84f6de92007-02-13 10:10:39 +0000562 try:
563 zf = zipfile.ZipFile(TESTFN, 'a')
564 zf.writestr(filename, content)
565 zf.close()
566 except IOError, (errno, errmsg):
567 self.fail('Could not append data to a non-existent zip file.')
568
569 self.assert_(os.path.exists(TESTFN))
570
571 zf = zipfile.ZipFile(TESTFN, 'r')
572 self.assertEqual(zf.read(filename), content)
573 zf.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000574
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000575 def testCloseErroneousFile(self):
576 # This test checks that the ZipFile constructor closes the file object
577 # it opens if there's an error in the file. If it doesn't, the traceback
578 # holds a reference to the ZipFile object and, indirectly, the file object.
579 # On Windows, this causes the os.unlink() call to fail because the
580 # underlying file is still open. This is SF bug #412214.
581 #
582 fp = open(TESTFN, "w")
583 fp.write("this is not a legal zip file\n")
584 fp.close()
585 try:
586 zf = zipfile.ZipFile(TESTFN)
587 except zipfile.BadZipfile:
Collin Winter04a51ec2007-03-29 02:28:16 +0000588 pass
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000589
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000590 def testIsZipErroneousFile(self):
Tim Petersea5962f2007-03-12 18:07:52 +0000591 # This test checks that the is_zipfile function correctly identifies
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000592 # a file that is not a zip file
593 fp = open(TESTFN, "w")
594 fp.write("this is not a legal zip file\n")
595 fp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000596 chk = zipfile.is_zipfile(TESTFN)
Tim Petersea5962f2007-03-12 18:07:52 +0000597 self.assert_(chk is False)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000598
599 def testIsZipValidFile(self):
Tim Petersea5962f2007-03-12 18:07:52 +0000600 # This test checks that the is_zipfile function correctly identifies
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000601 # a file that is a zip file
602 zipf = zipfile.ZipFile(TESTFN, mode="w")
603 zipf.writestr("foo.txt", "O, for a Muse of Fire!")
604 zipf.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000605 chk = zipfile.is_zipfile(TESTFN)
Tim Petersea5962f2007-03-12 18:07:52 +0000606 self.assert_(chk is True)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000607
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000608 def testNonExistentFileRaisesIOError(self):
609 # make sure we don't raise an AttributeError when a partially-constructed
610 # ZipFile instance is finalized; this tests for regression on SF tracker
611 # bug #403871.
612
613 # The bug we're testing for caused an AttributeError to be raised
614 # when a ZipFile instance was created for a file that did not
615 # exist; the .fp member was not initialized but was needed by the
616 # __del__() method. Since the AttributeError is in the __del__(),
617 # it is ignored, but the user should be sufficiently annoyed by
618 # the message on the output that regression will be noticed
619 # quickly.
620 self.assertRaises(IOError, zipfile.ZipFile, TESTFN)
621
622 def testClosedZipRaisesRuntimeError(self):
623 # Verify that testzip() doesn't swallow inappropriate exceptions.
624 data = StringIO()
625 zipf = zipfile.ZipFile(data, mode="w")
626 zipf.writestr("foo.txt", "O, for a Muse of Fire!")
627 zipf.close()
628
629 # This is correct; calling .read on a closed ZipFile should throw
630 # a RuntimeError, and so should calling .testzip. An earlier
631 # version of .testzip would swallow this exception (and any other)
632 # and report that the first file in the archive was corrupt.
Georg Brandl4b3ab6f2007-07-12 09:59:22 +0000633 self.assertRaises(RuntimeError, zipf.read, "foo.txt")
634 self.assertRaises(RuntimeError, zipf.open, "foo.txt")
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000635 self.assertRaises(RuntimeError, zipf.testzip)
Georg Brandl4b3ab6f2007-07-12 09:59:22 +0000636 self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus")
637 file(TESTFN, 'w').write('zipfile test data')
638 self.assertRaises(RuntimeError, zipf.write, TESTFN)
639
640 def test_BadConstructorMode(self):
641 # Check that bad modes passed to ZipFile constructor are caught
642 self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "q")
643
644 def test_BadOpenMode(self):
645 # Check that bad modes passed to ZipFile.open are caught
646 zipf = zipfile.ZipFile(TESTFN, mode="w")
647 zipf.writestr("foo.txt", "O, for a Muse of Fire!")
648 zipf.close()
649 zipf = zipfile.ZipFile(TESTFN, mode="r")
650 # read the data to make sure the file is there
651 zipf.read("foo.txt")
652 self.assertRaises(RuntimeError, zipf.open, "foo.txt", "q")
653 zipf.close()
654
655 def test_Read0(self):
656 # Check that calling read(0) on a ZipExtFile object returns an empty
657 # string and doesn't advance file pointer
658 zipf = zipfile.ZipFile(TESTFN, mode="w")
659 zipf.writestr("foo.txt", "O, for a Muse of Fire!")
660 # read the data to make sure the file is there
661 f = zipf.open("foo.txt")
662 for i in xrange(FIXEDTEST_SIZE):
663 self.assertEqual(f.read(0), '')
664
665 self.assertEqual(f.read(), "O, for a Muse of Fire!")
666 zipf.close()
667
668 def test_OpenNonexistentItem(self):
669 # Check that attempting to call open() for an item that doesn't
670 # exist in the archive raises a RuntimeError
671 zipf = zipfile.ZipFile(TESTFN, mode="w")
672 self.assertRaises(KeyError, zipf.open, "foo.txt", "r")
673
674 def test_BadCompressionMode(self):
675 # Check that bad compression methods passed to ZipFile.open are caught
676 self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1)
677
678 def test_NullByteInFilename(self):
679 # Check that a filename containing a null byte is properly terminated
680 zipf = zipfile.ZipFile(TESTFN, mode="w")
681 zipf.writestr("foo.txt\x00qqq", "O, for a Muse of Fire!")
682 self.assertEqual(zipf.namelist(), ['foo.txt'])
Neal Norwitz0d4c06e2007-04-25 06:30:05 +0000683
Collin Winter04a51ec2007-03-29 02:28:16 +0000684 def tearDown(self):
685 support.unlink(TESTFN)
686 support.unlink(TESTFN2)
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000687
Martin v. Löwisc6d626e2007-02-13 09:49:38 +0000688class DecryptionTests(unittest.TestCase):
689 # This test checks that ZIP decryption works. Since the library does not
690 # support encryption at the moment, we use a pre-generated encrypted
691 # ZIP file
692
693 data = (
694 'PK\x03\x04\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00\x1a\x00'
695 '\x00\x00\x08\x00\x00\x00test.txt\xfa\x10\xa0gly|\xfa-\xc5\xc0=\xf9y'
696 '\x18\xe0\xa8r\xb3Z}Lg\xbc\xae\xf9|\x9b\x19\xe4\x8b\xba\xbb)\x8c\xb0\xdbl'
697 'PK\x01\x02\x14\x00\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00'
698 '\x1a\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01\x00 \x00\xb6\x81'
699 '\x00\x00\x00\x00test.txtPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00'
700 '\x00\x00L\x00\x00\x00\x00\x00' )
701
702 plain = 'zipfile.py encryption test'
703
704 def setUp(self):
705 fp = open(TESTFN, "wb")
706 fp.write(self.data)
707 fp.close()
708 self.zip = zipfile.ZipFile(TESTFN, "r")
709
710 def tearDown(self):
711 self.zip.close()
712 os.unlink(TESTFN)
713
714 def testNoPassword(self):
715 # Reading the encrypted file without password
716 # must generate a RunTime exception
717 self.assertRaises(RuntimeError, self.zip.read, "test.txt")
718
719 def testBadPassword(self):
720 self.zip.setpassword("perl")
721 self.assertRaises(RuntimeError, self.zip.read, "test.txt")
Tim Petersea5962f2007-03-12 18:07:52 +0000722
Martin v. Löwisc6d626e2007-02-13 09:49:38 +0000723 def testGoodPassword(self):
724 self.zip.setpassword("python")
725 self.assertEquals(self.zip.read("test.txt"), self.plain)
726
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000727
728class TestsWithRandomBinaryFiles(unittest.TestCase):
729 def setUp(self):
730 datacount = randint(16, 64)*1024 + randint(1, 1024)
731 self.data = ''.join((struct.pack('<f', random()*randint(-1000, 1000)) for i in xrange(datacount)))
732
733 # Make a source file with some lines
734 fp = open(TESTFN, "wb")
735 fp.write(self.data)
736 fp.close()
Neal Norwitz0d4c06e2007-04-25 06:30:05 +0000737
Collin Winter04a51ec2007-03-29 02:28:16 +0000738 def tearDown(self):
739 support.unlink(TESTFN)
740 support.unlink(TESTFN2)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000741
742 def makeTestArchive(self, f, compression):
743 # Create the ZIP archive
744 zipfp = zipfile.ZipFile(f, "w", compression)
745 zipfp.write(TESTFN, "another"+os.extsep+"name")
746 zipfp.write(TESTFN, TESTFN)
747 zipfp.close()
748
749 def zipTest(self, f, compression):
750 self.makeTestArchive(f, compression)
751
752 # Read the ZIP archive
753 zipfp = zipfile.ZipFile(f, "r", compression)
754 testdata = zipfp.read(TESTFN)
755 self.assertEqual(len(testdata), len(self.data))
756 self.assertEqual(testdata, self.data)
757 self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
758 zipfp.close()
759
760 def testStored(self):
761 for f in (TESTFN2, TemporaryFile(), StringIO()):
762 self.zipTest(f, zipfile.ZIP_STORED)
Tim Petersea5962f2007-03-12 18:07:52 +0000763
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000764 def zipOpenTest(self, f, compression):
765 self.makeTestArchive(f, compression)
766
767 # Read the ZIP archive
768 zipfp = zipfile.ZipFile(f, "r", compression)
769 zipdata1 = []
770 zipopen1 = zipfp.open(TESTFN)
771 while 1:
772 read_data = zipopen1.read(256)
773 if not read_data:
774 break
775 zipdata1.append(read_data)
776
777 zipdata2 = []
778 zipopen2 = zipfp.open("another"+os.extsep+"name")
779 while 1:
780 read_data = zipopen2.read(256)
781 if not read_data:
782 break
783 zipdata2.append(read_data)
Tim Petersea5962f2007-03-12 18:07:52 +0000784
785 testdata1 = ''.join(zipdata1)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000786 self.assertEqual(len(testdata1), len(self.data))
787 self.assertEqual(testdata1, self.data)
788
Tim Petersea5962f2007-03-12 18:07:52 +0000789 testdata2 = ''.join(zipdata2)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000790 self.assertEqual(len(testdata1), len(self.data))
791 self.assertEqual(testdata1, self.data)
792 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000793
794 def testOpenStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000795 for f in (TESTFN2, TemporaryFile(), StringIO()):
796 self.zipOpenTest(f, zipfile.ZIP_STORED)
797
798 def zipRandomOpenTest(self, f, compression):
799 self.makeTestArchive(f, compression)
800
801 # Read the ZIP archive
802 zipfp = zipfile.ZipFile(f, "r", compression)
803 zipdata1 = []
804 zipopen1 = zipfp.open(TESTFN)
805 while 1:
806 read_data = zipopen1.read(randint(1, 1024))
807 if not read_data:
808 break
809 zipdata1.append(read_data)
810
811 testdata = ''.join(zipdata1)
812 self.assertEqual(len(testdata), len(self.data))
813 self.assertEqual(testdata, self.data)
814 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000815
816 def testRandomOpenStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000817 for f in (TESTFN2, TemporaryFile(), StringIO()):
818 self.zipRandomOpenTest(f, zipfile.ZIP_STORED)
819
820class TestsWithMultipleOpens(unittest.TestCase):
821 def setUp(self):
822 # Create the ZIP archive
823 zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
824 zipfp.writestr('ones', '1'*FIXEDTEST_SIZE)
825 zipfp.writestr('twos', '2'*FIXEDTEST_SIZE)
826 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000827
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000828 def testSameFile(self):
829 # Verify that (when the ZipFile is in control of creating file objects)
830 # multiple open() calls can be made without interfering with each other.
831 zipf = zipfile.ZipFile(TESTFN2, mode="r")
832 zopen1 = zipf.open('ones')
833 zopen2 = zipf.open('ones')
834 data1 = zopen1.read(500)
835 data2 = zopen2.read(500)
836 data1 += zopen1.read(500)
837 data2 += zopen2.read(500)
838 self.assertEqual(data1, data2)
839 zipf.close()
840
841 def testDifferentFile(self):
842 # Verify that (when the ZipFile is in control of creating file objects)
843 # multiple open() calls can be made without interfering with each other.
844 zipf = zipfile.ZipFile(TESTFN2, mode="r")
845 zopen1 = zipf.open('ones')
846 zopen2 = zipf.open('twos')
847 data1 = zopen1.read(500)
848 data2 = zopen2.read(500)
849 data1 += zopen1.read(500)
850 data2 += zopen2.read(500)
851 self.assertEqual(data1, '1'*FIXEDTEST_SIZE)
852 self.assertEqual(data2, '2'*FIXEDTEST_SIZE)
853 zipf.close()
854
855 def testInterleaved(self):
856 # Verify that (when the ZipFile is in control of creating file objects)
857 # multiple open() calls can be made without interfering with each other.
858 zipf = zipfile.ZipFile(TESTFN2, mode="r")
859 zopen1 = zipf.open('ones')
860 data1 = zopen1.read(500)
861 zopen2 = zipf.open('twos')
862 data2 = zopen2.read(500)
863 data1 += zopen1.read(500)
864 data2 += zopen2.read(500)
865 self.assertEqual(data1, '1'*FIXEDTEST_SIZE)
866 self.assertEqual(data2, '2'*FIXEDTEST_SIZE)
867 zipf.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000868
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000869 def tearDown(self):
870 os.remove(TESTFN2)
Tim Petersea5962f2007-03-12 18:07:52 +0000871
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000872
873class UniversalNewlineTests(unittest.TestCase):
874 def setUp(self):
875 self.line_gen = ["Test of zipfile line %d." % i for i in xrange(FIXEDTEST_SIZE)]
876 self.seps = ('\r', '\r\n', '\n')
877 self.arcdata, self.arcfiles = {}, {}
878 for n, s in enumerate(self.seps):
879 self.arcdata[s] = s.join(self.line_gen) + s
880 self.arcfiles[s] = '%s-%d' % (TESTFN, n)
Brett Cannon6cef0762007-05-25 20:17:15 +0000881 open(self.arcfiles[s], "wb").write(self.arcdata[s])
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000882
883 def makeTestArchive(self, f, compression):
884 # Create the ZIP archive
885 zipfp = zipfile.ZipFile(f, "w", compression)
886 for fn in self.arcfiles.values():
887 zipfp.write(fn, fn)
888 zipfp.close()
889
890 def readTest(self, f, compression):
891 self.makeTestArchive(f, compression)
892
893 # Read the ZIP archive
894 zipfp = zipfile.ZipFile(f, "r")
895 for sep, fn in self.arcfiles.items():
896 zipdata = zipfp.open(fn, "rU").read()
897 self.assertEqual(self.arcdata[sep], zipdata)
898
899 zipfp.close()
Tim Petersea5962f2007-03-12 18:07:52 +0000900
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000901 def readlineTest(self, f, compression):
902 self.makeTestArchive(f, compression)
903
904 # Read the ZIP archive
905 zipfp = zipfile.ZipFile(f, "r")
906 for sep, fn in self.arcfiles.items():
907 zipopen = zipfp.open(fn, "rU")
908 for line in self.line_gen:
909 linedata = zipopen.readline()
910 self.assertEqual(linedata, line + '\n')
911
912 zipfp.close()
913
914 def readlinesTest(self, f, compression):
915 self.makeTestArchive(f, compression)
916
917 # Read the ZIP archive
918 zipfp = zipfile.ZipFile(f, "r")
919 for sep, fn in self.arcfiles.items():
920 ziplines = zipfp.open(fn, "rU").readlines()
921 for line, zipline in zip(self.line_gen, ziplines):
922 self.assertEqual(zipline, line + '\n')
923
924 zipfp.close()
925
926 def iterlinesTest(self, f, compression):
927 self.makeTestArchive(f, compression)
928
929 # Read the ZIP archive
930 zipfp = zipfile.ZipFile(f, "r")
931 for sep, fn in self.arcfiles.items():
932 for line, zipline in zip(self.line_gen, zipfp.open(fn, "rU")):
933 self.assertEqual(zipline, line + '\n')
934
935 zipfp.close()
936
Tim Petersea5962f2007-03-12 18:07:52 +0000937 def testReadStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000938 for f in (TESTFN2, TemporaryFile(), StringIO()):
939 self.readTest(f, zipfile.ZIP_STORED)
Tim Petersea5962f2007-03-12 18:07:52 +0000940
941 def testReadlineStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000942 for f in (TESTFN2, TemporaryFile(), StringIO()):
943 self.readlineTest(f, zipfile.ZIP_STORED)
944
Tim Petersea5962f2007-03-12 18:07:52 +0000945 def testReadlinesStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000946 for f in (TESTFN2, TemporaryFile(), StringIO()):
947 self.readlinesTest(f, zipfile.ZIP_STORED)
948
Tim Petersea5962f2007-03-12 18:07:52 +0000949 def testIterlinesStored(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000950 for f in (TESTFN2, TemporaryFile(), StringIO()):
951 self.iterlinesTest(f, zipfile.ZIP_STORED)
Tim Petersea5962f2007-03-12 18:07:52 +0000952
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000953 if zlib:
Tim Petersea5962f2007-03-12 18:07:52 +0000954 def testReadDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000955 for f in (TESTFN2, TemporaryFile(), StringIO()):
956 self.readTest(f, zipfile.ZIP_DEFLATED)
957
Tim Petersea5962f2007-03-12 18:07:52 +0000958 def testReadlineDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000959 for f in (TESTFN2, TemporaryFile(), StringIO()):
960 self.readlineTest(f, zipfile.ZIP_DEFLATED)
961
Tim Petersea5962f2007-03-12 18:07:52 +0000962 def testReadlinesDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000963 for f in (TESTFN2, TemporaryFile(), StringIO()):
964 self.readlinesTest(f, zipfile.ZIP_DEFLATED)
965
Tim Petersea5962f2007-03-12 18:07:52 +0000966 def testIterlinesDeflated(self):
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000967 for f in (TESTFN2, TemporaryFile(), StringIO()):
968 self.iterlinesTest(f, zipfile.ZIP_DEFLATED)
969
970 def tearDown(self):
971 for sep, fn in self.arcfiles.items():
972 os.remove(fn)
Collin Winter04a51ec2007-03-29 02:28:16 +0000973 support.unlink(TESTFN)
974 support.unlink(TESTFN2)
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000975
976
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000977def test_main():
Tim Petersea5962f2007-03-12 18:07:52 +0000978 run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
979 PyZipFileTests, DecryptionTests, TestsWithMultipleOpens,
Martin v. Löwis3eb76482007-03-06 10:41:24 +0000980 UniversalNewlineTests, TestsWithRandomBinaryFiles)
981
Johannes Gijsbers3caf9c12004-08-19 15:11:50 +0000982if __name__ == "__main__":
983 test_main()