Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e7e485

Browse files
committed
Added regression test for SF tracker bug #403871: AttributeError in
ZipFile.__del__() when there was an IOError opening the underlying file in ZipFile.__init__(). This is an odd test: since the exception is in the __del__() method, it is not propogated. This test will trigger it but regrtest.py does not detect the failure (not sure why); we are dependent on it actually being noticed by a user to get a new bug report if it ever fails. ;-( On the other hand, this makes sure that code gets exercised, so a failure could be noticed!
1 parent 90eac28 commit 6e7e485

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/test/test_zipfile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import zipfile, os
2+
from test_support import TestFailed
23

34
srcname = "junk9630.tmp"
45
zipname = "junk9708.tmp"
@@ -23,3 +24,21 @@
2324
os.unlink(srcname)
2425
if os.path.isfile(zipname):
2526
os.unlink(zipname)
27+
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.")

0 commit comments

Comments
 (0)