summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-12 13:03:23 (GMT)
committerGitHub <noreply@github.com>2017-04-12 13:03:23 (GMT)
commit4c0d9ea995da595e90e08813b89510de59907802 (patch)
tree1c6138fb627ad1f5b982cc67dafd230d50f8cc27 /Lib/test/test_zipfile.py
parent3e0f1fc4e0ffcfcc706015fa3d67c262948ef171 (diff)
downloadcpython-4c0d9ea995da595e90e08813b89510de59907802.zip
cpython-4c0d9ea995da595e90e08813b89510de59907802.tar.gz
cpython-4c0d9ea995da595e90e08813b89510de59907802.tar.bz2
bpo-30017: Allowed calling the close() method of the zip entry writer object (#1041)
multiple times. Writing to closed zip entry writer object now always produce a ValueError.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 46a67d5..ff55e94 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -734,6 +734,48 @@ class LzmaTestZip64InSmallFiles(AbstractTestZip64InSmallFiles,
compression = zipfile.ZIP_LZMA
+class AbstractWriterTests:
+
+ def tearDown(self):
+ unlink(TESTFN2)
+
+ def test_close_after_close(self):
+ data = b'content'
+ with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipf:
+ w = zipf.open('test', 'w')
+ w.write(data)
+ w.close()
+ self.assertTrue(w.closed)
+ w.close()
+ self.assertTrue(w.closed)
+ self.assertEqual(zipf.read('test'), data)
+
+ def test_write_after_close(self):
+ data = b'content'
+ with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipf:
+ w = zipf.open('test', 'w')
+ w.write(data)
+ w.close()
+ self.assertTrue(w.closed)
+ self.assertRaises(ValueError, w.write, b'')
+ self.assertEqual(zipf.read('test'), data)
+
+class StoredWriterTests(AbstractWriterTests, unittest.TestCase):
+ compression = zipfile.ZIP_STORED
+
+@requires_zlib
+class DeflateWriterTests(AbstractWriterTests, unittest.TestCase):
+ compression = zipfile.ZIP_DEFLATED
+
+@requires_bz2
+class Bzip2WriterTests(AbstractWriterTests, unittest.TestCase):
+ compression = zipfile.ZIP_BZIP2
+
+@requires_lzma
+class LzmaWriterTests(AbstractWriterTests, unittest.TestCase):
+ compression = zipfile.ZIP_LZMA
+
+
class PyZipFileTests(unittest.TestCase):
def assertCompiledIn(self, name, namelist):
if name + 'o' not in namelist: