[Python-checkins] python/dist/src/Lib/test test_zipfile.py,1.9,1.10

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Fri, 27 Jun 2003 15:25:05 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv4923/Lib/test

Modified Files:
	test_zipfile.py 
Log Message:
SF patch #756996: Bare except in ZipFile.testzip()
(Contributed by Steven Taschuk)

Replaces a bare except that caused all errors to be mis-reported as
archive errors.

Added a related NEWS item.



Index: test_zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_zipfile.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** test_zipfile.py	23 Jul 2002 19:04:09 -0000	1.9
--- test_zipfile.py	27 Jun 2003 22:25:03 -0000	1.10
***************
*** 77,78 ****
--- 77,99 ----
      raise TestFailed("expected creation of readable ZipFile without\n"
                       "  a file to raise an IOError.")
+ 
+ 
+ # Verify that testzip() doesn't swallow inappropriate exceptions.
+ data = StringIO.StringIO()
+ zipf = zipfile.ZipFile(data, mode="w")
+ zipf.writestr("foo.txt", "O, for a Muse of Fire!")
+ zipf.close()
+ zipf = zipfile.ZipFile(data, mode="r")
+ zipf.close()
+ try:
+     zipf.testzip()
+ except RuntimeError:
+     # This is correct; calling .read on a closed ZipFile should throw
+     # a RuntimeError, and so should calling .testzip.  An earlier
+     # version of .testzip would swallow this exception (and any other)
+     # and report that the first file in the archive was corrupt.
+     pass
+ else:
+     raise TestFailed("expected calling .testzip on a closed ZipFile"
+                      " to raise a RuntimeError")
+ del data, zipf