summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 57f9a89..d21a9eb 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -76,3 +76,24 @@ except IOError:
else:
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