@@ -1149,22 +1149,24 @@ class LzmaWriterTests(AbstractWriterTests, unittest.TestCase):
1149
1149
1150
1150
class AbstractRemoveTests :
1151
1151
1152
- def _test_removing_members (self ,test_files ,indexes ):
1152
+ def _test_removing_members (self ,test_files ,indexes , force_zip64 = False ):
1153
1153
"""Test underlying _remove_members() for removing members at given
1154
1154
indexes."""
1155
1155
# calculate the expected results
1156
1156
expected_files = []
1157
1157
with zipfile .ZipFile (TESTFN ,'w' ,self .compression )as zh :
1158
1158
for i , (file ,data )in enumerate (test_files ):
1159
1159
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 )
1161
1162
expected_files .append (file )
1162
1163
expected_size = os .path .getsize (TESTFN )
1163
1164
1164
1165
# prepare the test zip
1165
1166
with zipfile .ZipFile (TESTFN ,'w' ,self .compression )as zh :
1166
1167
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 )
1168
1170
1169
1171
# do the removal and check the result
1170
1172
with zipfile .ZipFile (TESTFN ,'a' ,self .compression )as zh :
@@ -1337,30 +1339,13 @@ def test_verify(self):
1337
1339
1338
1340
def test_zip64 (self ):
1339
1341
"""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
+ ]
1352
1347
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 )
1364
1349
1365
1350
class StoredRemoveTests (AbstractRemoveTests ,unittest .TestCase ):
1366
1351
compression = zipfile .ZIP_STORED