mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
6f3eaa67e5
commit
c0fac96c29
3 changed files with 26 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue