[Python-checkins] CVS: python/dist/src/Lib/test test_zipfile.py,1.5,1.6
Tim Peters
tim_one@users.sourceforge.net
2001年4月04日 11:56:51 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv5351/python/dist/src/Lib/test
Modified Files:
test_zipfile.py
Log Message:
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.
Index: test_zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_zipfile.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** test_zipfile.py 2001年03月29日 04:36:09 1.5
--- test_zipfile.py 2001年04月04日 18:56:49 1.6
***************
*** 43,46 ****
--- 43,62 ----
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