summaryrefslogtreecommitdiff
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-11-26 07:22:28 +0000
committerGeorg Brandl <georg@python.org>2010-11-26 07:22:28 +0000
commit86e0c89b2a9c715939a7d7aee3dc271850eabd62 (patch)
tree679d9a26ebfcd4e116851b7ec709bf013c874d92 /Lib/test/test_zipfile.py
parent420cca92e8b1b5b9bd2b9a58a93d4e8f0ff86d1d (diff)
downloadcpython-git-86e0c89b2a9c715939a7d7aee3dc271850eabd62.tar.gz
Merged revisions 85455 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85455 | georg.brandl | 2010-10-14 08:59:45 +0200 (Do, 14 Okt 2010) | 1 line #1710703: write zipfile structures also in the case of closing a new, but empty, archive. ........
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index aee499ca73..ddd713f974 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -949,6 +949,31 @@ class OtherTests(unittest.TestCase):
def test_read_return_size_deflated(self):
self.check_read_return_size(zipfile.ZIP_DEFLATED)
+ def test_empty_zipfile(self):
+ # Check that creating a file in 'w' or 'a' mode and closing without
+ # adding any files to the archives creates a valid empty ZIP file
+ zipf = zipfile.ZipFile(TESTFN, mode="w")
+ zipf.close()
+ try:
+ zipf = zipfile.ZipFile(TESTFN, mode="r")
+ except zipfile.BadZipFile:
+ self.fail("Unable to create empty ZIP file in 'w' mode")
+
+ zipf = zipfile.ZipFile(TESTFN, mode="a")
+ zipf.close()
+ try:
+ zipf = zipfile.ZipFile(TESTFN, mode="r")
+ except:
+ self.fail("Unable to create empty ZIP file in 'a' mode")
+
+ def test_open_empty_file(self):
+ # Issue 1710703: Check that opening a file with less than 22 bytes
+ # raises a BadZipfile exception (rather than the previously unhelpful
+ # IOError)
+ f = open(TESTFN, 'w')
+ f.close()
+ self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN, 'r')
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)