diff options
author | Fred Drake <fdrake@acm.org> | 2001-03-26 15:49:24 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-03-26 15:49:24 (GMT) |
commit | 3d9091ece14ad53e48da7792245ebc4230df22e3 (patch) | |
tree | 1c86619e78a3a1b24f6b5b607f847d8727be1bc7 /Lib/test/test_zipfile.py | |
parent | fc31f2692f3cf022606b48534801f4371bf11001 (diff) | |
download | cpython-3d9091ece14ad53e48da7792245ebc4230df22e3.zip cpython-3d9091ece14ad53e48da7792245ebc4230df22e3.tar.gz cpython-3d9091ece14ad53e48da7792245ebc4230df22e3.tar.bz2 |
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.py | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 0dc080b..8da74f5 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) |