diff options
author | Raymond Hettinger <python@rcn.com> | 2003-06-27 22:25:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-06-27 22:25:03 (GMT) |
commit | c0fac96c29a3842d9370e4c954ae1f4d57f849d0 (patch) | |
tree | 79a674fa3d0b905a3d395ded0998cb56606ef298 /Lib/test | |
parent | 6f3eaa67e51ed0c1b493a26afdf4417d4105d96d (diff) | |
download | cpython-c0fac96c29a3842d9370e4c954ae1f4d57f849d0.zip cpython-c0fac96c29a3842d9370e4c954ae1f4d57f849d0.tar.gz cpython-c0fac96c29a3842d9370e4c954ae1f4d57f849d0.tar.bz2 |
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.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipfile.py | 21 |
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 |