summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_zipfile.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index ff4a6d6..5d7b91f 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -420,6 +420,49 @@ class StoredTestsWithSourceFile(AbstractTestsWithSourceFile,
f.seek(len(data))
with zipfile.ZipFile(f, "r") as zipfp:
self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+ with open(TESTFN2, 'rb') as f:
+ self.assertEqual(f.read(len(data)), data)
+ zipfiledata = f.read()
+ with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+
+ def test_read_concatenated_zip_file(self):
+ with io.BytesIO() as bio:
+ with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
+ zipfp.write(TESTFN, TESTFN)
+ zipfiledata = bio.getvalue()
+ data = b'I am not a ZipFile!'*10
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+ f.write(zipfiledata)
+
+ with zipfile.ZipFile(TESTFN2) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+
+ def test_append_to_concatenated_zip_file(self):
+ with io.BytesIO() as bio:
+ with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
+ zipfp.write(TESTFN, TESTFN)
+ zipfiledata = bio.getvalue()
+ data = b'I am not a ZipFile!'*1000000
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+ f.write(zipfiledata)
+
+ with zipfile.ZipFile(TESTFN2, 'a') as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ zipfp.writestr('strfile', self.data)
+
+ with open(TESTFN2, 'rb') as f:
+ self.assertEqual(f.read(len(data)), data)
+ zipfiledata = f.read()
+ with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN, 'strfile'])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+ self.assertEqual(zipfp.read('strfile'), self.data)
def test_ignores_newline_at_end(self):
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp: