summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-25 08:09:41 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-25 08:09:41 (GMT)
commit764fc9bfac84d564c526628974a9bd5edfa5bcab (patch)
tree84a9d8736869ad41ca0c5e17550fb14cb9afba34 /Lib/test/test_zipfile.py
parent489199765ff313d0a7dad70b8fbf416667c43862 (diff)
downloadcpython-764fc9bfac84d564c526628974a9bd5edfa5bcab.zip
cpython-764fc9bfac84d564c526628974a9bd5edfa5bcab.tar.gz
cpython-764fc9bfac84d564c526628974a9bd5edfa5bcab.tar.bz2
Issue #21717: The zipfile.ZipFile.open function now supports 'x' (exclusive
creation) mode.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 4cd5fe3..1b2dc85 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1104,6 +1104,19 @@ class OtherTests(unittest.TestCase):
self.assertEqual(zf.filelist[0].filename, "foo.txt")
self.assertEqual(zf.filelist[1].filename, "\xf6.txt")
+ def test_exclusive_create_zip_file(self):
+ """Test exclusive creating a new zipfile."""
+ unlink(TESTFN2)
+ filename = 'testfile.txt'
+ content = b'hello, world. this is some content.'
+ with zipfile.ZipFile(TESTFN2, "x", zipfile.ZIP_STORED) as zipfp:
+ zipfp.writestr(filename, content)
+ with self.assertRaises(FileExistsError):
+ zipfile.ZipFile(TESTFN2, "x", zipfile.ZIP_STORED)
+ with zipfile.ZipFile(TESTFN2, "r") as zipfp:
+ self.assertEqual(zipfp.namelist(), [filename])
+ self.assertEqual(zipfp.read(filename), content)
+
def test_create_non_existent_file_for_append(self):
if os.path.exists(TESTFN):
os.unlink(TESTFN)