Files for 2.1b1 distribution.
[python/dscho.git] / Lib / test / test_zipfile.py
blob0dc080b2ffdca692f8085605ffb2050dbd5f383c
1 import zipfile, os
2 from test_support import TestFailed
4 srcname = "junk9630.tmp"
5 zipname = "junk9708.tmp"
7 try:
8 fp = open(srcname, "w") # Make a source file with some lines
9 for i in range(0, 1000):
10 fp.write("Test of zipfile line %d.\n" % i)
11 fp.close()
13 zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
14 zip.write(srcname, srcname)
15 zip.write(srcname, "another.name")
16 zip.close()
18 zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive
19 zip.read("another.name")
20 zip.read(srcname)
21 zip.close()
22 finally:
23 if os.path.isfile(srcname): # Remove temporary files
24 os.unlink(srcname)
25 if os.path.isfile(zipname):
26 os.unlink(zipname)
28 # make sure we don't raise an AttributeError when a partially-constructed
29 # ZipFile instance is finalized; this tests for regression on SF tracker
30 # bug #403871.
31 try:
32 zipfile.ZipFile(srcname)
33 except IOError:
34 # The bug we're testing for caused an AttributeError to be raised
35 # when a ZipFile instance was created for a file that did not
36 # exist; the .fp member was not initialized but was needed by the
37 # __del__() method. Since the AttributeError is in the __del__(),
38 # it is ignored, but the user should be sufficiently annoyed by
39 # the message on the output that regression will be noticed
40 # quickly.
41 pass
42 else:
43 raise TestFailed("expected creation of readable ZipFile without\n"
44 " a file to raise an IOError.")