summaryrefslogtreecommitdiff
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-03-26 15:49:24 +0000
committerFred Drake <fdrake@acm.org>2001-03-26 15:49:24 +0000
commit3999e0ffe98714103c70c6153dad5cfe983715ae (patch)
treefcffa6b778a2c7aaae414a4ea41206c33c75f73e /Lib/test/test_zipfile.py
parent1c4d98e776bd38427bf13a40081f079426a50adc (diff)
downloadcpython-3999e0ffe98714103c70c6153dad5cfe983715ae.tar.gz
Itamar Shtull-Trauring <itamar@maxnm.com>:
Add support to zipfile to support opening an archive represented by an open file rather than a file name.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 0dc080b2ff..8da74f58bd 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1,24 +1,41 @@
-import zipfile, os
+import zipfile, os, StringIO, tempfile
from test_support import TestFailed
srcname = "junk9630.tmp"
zipname = "junk9708.tmp"
+
+def zipTest(f, compression, srccontents):
+ zip = zipfile.ZipFile(f, "w", compression) # Create the ZIP archive
+ zip.write(srcname, "another.name")
+ zip.write(srcname, srcname)
+ zip.close()
+
+ zip = zipfile.ZipFile(f, "r", compression) # Read the ZIP archive
+ readData2 = zip.read(srcname)
+ readData1 = zip.read("another.name")
+ zip.close()
+
+ if readData1 != srccontents or readData2 != srccontents:
+ raise TestFailed, "Written data doesn't equal read data."
+
+
try:
- fp = open(srcname, "w") # Make a source file with some lines
+ fp = open(srcname, "wb") # Make a source file with some lines
for i in range(0, 1000):
fp.write("Test of zipfile line %d.\n" % i)
fp.close()
+
+ fp = open(srcname, "rb")
+ writtenData = fp.read()
+ fp.close()
+
+ for file in (zipname, tempfile.TemporaryFile(), StringIO.StringIO()):
+ zipTest(file, zipfile.ZIP_STORED, writtenData)
- zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
- zip.write(srcname, srcname)
- zip.write(srcname, "another.name")
- zip.close()
+ for file in (zipname, tempfile.TemporaryFile(), StringIO.StringIO()):
+ zipTest(file, zipfile.ZIP_DEFLATED, writtenData)
- zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive
- zip.read("another.name")
- zip.read(srcname)
- zip.close()
finally:
if os.path.isfile(srcname): # Remove temporary files
os.unlink(srcname)