mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
This commit is contained in:
commit
c46d1faa4a
3 changed files with 15 additions and 9 deletions
|
@ -646,7 +646,7 @@ class PyZipFileTests(unittest.TestCase):
|
|||
self.assertTrue('SyntaxError' not in reportStr)
|
||||
|
||||
# then check that the filter works on individual files
|
||||
with captured_stdout() as reportSIO:
|
||||
with captured_stdout() as reportSIO, self.assertWarns(UserWarning):
|
||||
zipfp.writepy(packagedir, filterfunc=lambda fn:
|
||||
'bad' not in fn)
|
||||
reportStr = reportSIO.getvalue()
|
||||
|
@ -896,7 +896,9 @@ class OtherTests(unittest.TestCase):
|
|||
# Create the ZIP archive
|
||||
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
|
||||
zipfp.writestr("name", "foo")
|
||||
zipfp.writestr("name", "bar")
|
||||
with self.assertWarns(UserWarning):
|
||||
zipfp.writestr("name", "bar")
|
||||
self.assertEqual(zipfp.namelist(), ["name"] * 2)
|
||||
|
||||
with zipfile.ZipFile(TESTFN2, "r") as zipfp:
|
||||
infos = zipfp.infolist()
|
||||
|
@ -1213,7 +1215,8 @@ class OtherTests(unittest.TestCase):
|
|||
|
||||
# check a comment that is too long is truncated
|
||||
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
|
||||
zipf.comment = comment2 + b'oops'
|
||||
with self.assertWarns(UserWarning):
|
||||
zipf.comment = comment2 + b'oops'
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
|
||||
self.assertEqual(zipfr.comment, comment2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue