summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-04-04 18:56:49 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-04-04 18:56:49 (GMT)
commit7d3bad66e4b32fa65fce219661b16d75e90c152f (patch)
tree20b242735b0cac4324c18e4a159d00b5638a8414 /Lib/test
parent42fc7ccdac459a5a37cba83e4585611e7e7fdb86 (diff)
downloadcpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.zip
cpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.tar.gz
cpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.tar.bz2
Sf bug [ #412214 ] ZipFile constructor leaves files open.
This applies the patch Fred Drake created to fix it. I'm checking it in since I had to apply the patch anyway in order to test its behavior on Windows.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_zipfile.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 50b8b36..bf7770b 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -42,6 +42,22 @@ finally:
if os.path.isfile(zipname):
os.unlink(zipname)
+
+# This test checks that the ZipFile constructor closes the file object
+# it opens if there's an error in the file. If it doesn't, the traceback
+# holds a reference to the ZipFile object and, indirectly, the file object.
+# On Windows, this causes the os.unlink() call to fail because the
+# underlying file is still open. This is SF bug #412214.
+#
+fp = open(srcname, "w")
+fp.write("this is not a legal zip file\n")
+fp.close()
+try:
+ zf = zipfile.ZipFile(srcname)
+except zipfile.BadZipfile:
+ os.unlink(srcname)
+
+
# make sure we don't raise an AttributeError when a partially-constructed
# ZipFile instance is finalized; this tests for regression on SF tracker
# bug #403871.