Skip to content

Commit

Permalink
Adapt python tests to use and test zipfile2.ZipFile
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos committed Oct 5, 2024
1 parent 97f5027 commit 8f433be
Show file tree
Hide file tree
Showing 17 changed files with 697 additions and 1,638 deletions.
428 changes: 215 additions & 213 deletions cpython-tests/3.10/test_zipfile.py

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions cpython-tests/3.10/test_zipfile64.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from test.support import os_helper
from test.support import requires_zlib

import zipfile2

TESTFN = os_helper.TESTFN
TESTFN2 = TESTFN + "2"

Expand All @@ -38,7 +40,7 @@ def setUp(self):

def zipTest(self, f, compression):
# Create the ZIP archive.
with zipfile.ZipFile(f, "w", compression) as zipfp:
with zipfile2.ZipFile(f, "w", compression) as zipfp:

# It will contain enough copies of self.data to reach about 6 GiB of
# raw data to store.
Expand All @@ -56,7 +58,7 @@ def zipTest(self, f, compression):
sys.__stdout__.flush()

# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
with zipfile2.ZipFile(f, "r", compression) as zipfp:
for num in range(filecount):
self.assertEqual(zipfp.read("testfn%d" % num), self.data)
# Print still working message since this test can be really slow
Expand Down Expand Up @@ -94,21 +96,21 @@ class OtherTests(unittest.TestCase):
def testMoreThan64kFiles(self):
# This test checks that more than 64k files can be added to an archive,
# and that the resulting archive can be read properly by ZipFile
with zipfile.ZipFile(TESTFN, mode="w", allowZip64=True) as zipf:
with zipfile2.ZipFile(TESTFN, mode="w", allowZip64=True) as zipf:
zipf.debug = 100
numfiles = (1 << 16) * 3//2
for i in range(numfiles):
zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
self.assertEqual(len(zipf.namelist()), numfiles)

with zipfile.ZipFile(TESTFN, mode="r") as zipf2:
with zipfile2.ZipFile(TESTFN, mode="r") as zipf2:
self.assertEqual(len(zipf2.namelist()), numfiles)
for i in range(numfiles):
content = zipf2.read("foo%08d" % i).decode('ascii')
self.assertEqual(content, "%d" % (i**3 % 57))

def testMoreThan64kFilesAppend(self):
with zipfile.ZipFile(TESTFN, mode="w", allowZip64=False) as zipf:
with zipfile2.ZipFile(TESTFN, mode="w", allowZip64=False) as zipf:
zipf.debug = 100
numfiles = (1 << 16) - 1
for i in range(numfiles):
Expand All @@ -118,22 +120,22 @@ def testMoreThan64kFilesAppend(self):
zipf.writestr("foo%08d" % numfiles, b'')
self.assertEqual(len(zipf.namelist()), numfiles)

with zipfile.ZipFile(TESTFN, mode="a", allowZip64=False) as zipf:
with zipfile2.ZipFile(TESTFN, mode="a", allowZip64=False) as zipf:
zipf.debug = 100
self.assertEqual(len(zipf.namelist()), numfiles)
with self.assertRaises(zipfile.LargeZipFile):
zipf.writestr("foo%08d" % numfiles, b'')
self.assertEqual(len(zipf.namelist()), numfiles)

with zipfile.ZipFile(TESTFN, mode="a", allowZip64=True) as zipf:
with zipfile2.ZipFile(TESTFN, mode="a", allowZip64=True) as zipf:
zipf.debug = 100
self.assertEqual(len(zipf.namelist()), numfiles)
numfiles2 = (1 << 16) * 3//2
for i in range(numfiles, numfiles2):
zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
self.assertEqual(len(zipf.namelist()), numfiles2)

with zipfile.ZipFile(TESTFN, mode="r") as zipf2:
with zipfile2.ZipFile(TESTFN, mode="r") as zipf2:
self.assertEqual(len(zipf2.namelist()), numfiles2)
for i in range(numfiles2):
content = zipf2.read("foo%08d" % i).decode('ascii')
Expand Down
4 changes: 3 additions & 1 deletion cpython-tests/3.10/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from test.support import import_helper
from test.support import os_helper

from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
from zipfile import ZipInfo, ZIP_STORED, ZIP_DEFLATED

import zipimport
import linecache
Expand All @@ -26,6 +26,8 @@
except ImportError:
zlib = None

from zipfile2 import ZipFile

test_src = """\
def get_name():
return __name__
Expand Down
243 changes: 0 additions & 243 deletions cpython-tests/3.10/test_zipimport_support.py

This file was deleted.

Loading

0 comments on commit 8f433be

Please sign in to comment.