Skip to content

Commit 692260e

Browse files
committed
Test for zip64 more thoroughly
1 parent e166f27 commit 692260e

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,22 +1149,24 @@ class LzmaWriterTests(AbstractWriterTests, unittest.TestCase):
11491149

11501150
class AbstractRemoveTests:
11511151

1152-
def _test_removing_members(self, test_files, indexes):
1152+
def _test_removing_members(self, test_files, indexes, force_zip64=False):
11531153
"""Test underlying _remove_members() for removing members at given
11541154
indexes."""
11551155
# calculate the expected results
11561156
expected_files = []
11571157
with zipfile.ZipFile(TESTFN, 'w', self.compression) as zh:
11581158
for i, (file, data) in enumerate(test_files):
11591159
if i not in indexes:
1160-
zh.writestr(file, data)
1160+
with zh.open(file, 'w', force_zip64=force_zip64) as fh:
1161+
fh.write(data)
11611162
expected_files.append(file)
11621163
expected_size = os.path.getsize(TESTFN)
11631164

11641165
# prepare the test zip
11651166
with zipfile.ZipFile(TESTFN, 'w', self.compression) as zh:
11661167
for file, data in test_files:
1167-
zh.writestr(file, data)
1168+
with zh.open(file, 'w', force_zip64=force_zip64) as fh:
1169+
fh.write(data)
11681170

11691171
# do the removal and check the result
11701172
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
@@ -1337,30 +1339,13 @@ def test_verify(self):
13371339

13381340
def test_zip64(self):
13391341
"""Test if members use zip64."""
1340-
file = 'datafile.txt'
1341-
file1 = 'pre.txt'
1342-
file2 = 'post.txt'
1343-
data = b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'
1344-
data1 = b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
1345-
data2 = b'Duis aute irure dolor in reprehenderit in voluptate velit esse'
1346-
with zipfile.ZipFile(TESTFN, 'w', self.compression) as zh:
1347-
with zh.open(file1, 'w', force_zip64=True) as fh:
1348-
fh.write(data1)
1349-
with zh.open(file2, 'w', force_zip64=True) as fh:
1350-
fh.write(data2)
1351-
expected_size = os.path.getsize(TESTFN)
1342+
test_files = [
1343+
('pre.txt', b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'),
1344+
('datafile', b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'),
1345+
('post.txt', b'Duis aute irure dolor in reprehenderit in voluptate velit esse'),
1346+
]
13521347

1353-
with zipfile.ZipFile(TESTFN, 'w', self.compression) as zh:
1354-
with zh.open(file1, 'w', force_zip64=True) as fh:
1355-
fh.write(data1)
1356-
with zh.open(file, 'w', force_zip64=True) as fh:
1357-
fh.write(data)
1358-
with zh.open(file2, 'w', force_zip64=True) as fh:
1359-
fh.write(data2)
1360-
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
1361-
zh.remove(file)
1362-
self.assertIsNone(zh.testzip())
1363-
self.assertEqual(os.path.getsize(TESTFN), expected_size)
1348+
self._test_removing_members(test_files, [1], force_zip64=True)
13641349

13651350
class StoredRemoveTests(AbstractRemoveTests, unittest.TestCase):
13661351
compression = zipfile.ZIP_STORED

0 commit comments

Comments
 (0)