2 from test_support
import TestFailed
4 srcname
= "junk9630.tmp"
5 zipname
= "junk9708.tmp"
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
)
13 zip = zipfile
.ZipFile(zipname
, "w") # Create the ZIP archive
14 zip.write(srcname
, srcname
)
15 zip.write(srcname
, "another.name")
18 zip = zipfile
.ZipFile(zipname
, "r") # Read the ZIP archive
19 zip.read("another.name")
23 if os
.path
.isfile(srcname
): # Remove temporary files
25 if os
.path
.isfile(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
32 zipfile
.ZipFile(srcname
)
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
43 raise TestFailed("expected creation of readable ZipFile without\n"
44 " a file to raise an IOError.")