@@ -1362,22 +1362,24 @@ class ZstdWriterTests(AbstractWriterTests, unittest.TestCase):
13621362
13631363class AbstractRemoveTests :
13641364
1365- def _test_removing_members (self , test_files , indexes ):
1365+ def _test_removing_members (self , test_files , indexes , force_zip64 = False ):
13661366 """Test underlying _remove_members() for removing members at given
13671367 indexes."""
13681368 # calculate the expected results
13691369 expected_files = []
13701370 with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
13711371 for i , (file , data ) in enumerate (test_files ):
13721372 if i not in indexes :
1373- zh .writestr (file , data )
1373+ with zh .open (file , 'w' , force_zip64 = force_zip64 ) as fh :
1374+ fh .write (data )
13741375 expected_files .append (file )
13751376 expected_size = os .path .getsize (TESTFN )
13761377
13771378 # prepare the test zip
13781379 with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
13791380 for file , data in test_files :
1380- zh .writestr (file , data )
1381+ with zh .open (file , 'w' , force_zip64 = force_zip64 ) as fh :
1382+ fh .write (data )
13811383
13821384 # do the removal and check the result
13831385 with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
@@ -1550,30 +1552,13 @@ def test_verify(self):
15501552
15511553 def test_zip64 (self ):
15521554 """Test if members use zip64."""
1553- file = 'datafile.txt'
1554- file1 = 'pre.txt'
1555- file2 = 'post.txt'
1556- data = b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'
1557- data1 = b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
1558- data2 = b'Duis aute irure dolor in reprehenderit in voluptate velit esse'
1559- with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
1560- with zh .open (file1 , 'w' , force_zip64 = True ) as fh :
1561- fh .write (data1 )
1562- with zh .open (file2 , 'w' , force_zip64 = True ) as fh :
1563- fh .write (data2 )
1564- expected_size = os .path .getsize (TESTFN )
1555+ test_files = [
1556+ ('pre.txt' , b'Lorem ipsum dolor sit amet, consectetur adipiscing elit' ),
1557+ ('datafile' , b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem' ),
1558+ ('post.txt' , b'Duis aute irure dolor in reprehenderit in voluptate velit esse' ),
1559+ ]
15651560
1566- with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
1567- with zh .open (file1 , 'w' , force_zip64 = True ) as fh :
1568- fh .write (data1 )
1569- with zh .open (file , 'w' , force_zip64 = True ) as fh :
1570- fh .write (data )
1571- with zh .open (file2 , 'w' , force_zip64 = True ) as fh :
1572- fh .write (data2 )
1573- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1574- zh .remove (file )
1575- self .assertIsNone (zh .testzip ())
1576- self .assertEqual (os .path .getsize (TESTFN ), expected_size )
1561+ self ._test_removing_members (test_files , [1 ], force_zip64 = True )
15771562
15781563class StoredRemoveTests (AbstractRemoveTests , unittest .TestCase ):
15791564 compression = zipfile .ZIP_STORED
0 commit comments