[Python-checkins] CVS: python/dist/src/Lib/test test_zipfile.py,1.3,1.4
Fred L. Drake
fdrake@users.sourceforge.net
Mon, 26 Mar 2001 07:49:26 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv10309/test
Modified Files:
test_zipfile.py
Log Message:
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.
Index: test_zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_zipfile.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_zipfile.py 2001/02/28 05:34:16 1.3
--- test_zipfile.py 2001/03/26 15:49:24 1.4
***************
*** 1,3 ****
! import zipfile, os
from test_support import TestFailed
--- 1,3 ----
! import zipfile, os, StringIO, tempfile
from test_support import TestFailed
***************
*** 5,23 ****
zipname = "junk9708.tmp"
try:
! fp = open(srcname, "w") # Make a source file with some lines
for i in range(0, 1000):
fp.write("Test of zipfile line %d.\n" % i)
fp.close()
! zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
! zip.write(srcname, srcname)
! zip.write(srcname, "another.name")
! zip.close()
- 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
--- 5,40 ----
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, "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)
! for file in (zipname, tempfile.TemporaryFile(), StringIO.StringIO()):
! zipTest(file, zipfile.ZIP_DEFLATED, writtenData)
finally:
if os.path.isfile(srcname): # Remove temporary files