@@ -2020,64 +2020,9 @@ def test_repack_prepended_bytes(self):
20202020 fh .write (b'dummy ' )
20212021 fh .write (fz .read ())
20222022 with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
2023- self .assertEqual (zh .data_offset , 6 )
20242023 for i in ii :
20252024 zh .remove (self .test_files [i ][0 ])
20262025 zh .repack ()
2027- if hasattr (zh , 'data_offset' ):
2028- self .assertEqual (zh .data_offset , 6 )
2029-
2030- # check infolist
2031- self .assertEqual (
2032- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
2033- [ComparableZipInfo (zi ) for zi in expected_zinfos ],
2034- )
2035-
2036- # check file size
2037- self .assertEqual (os .path .getsize (TESTFN ), expected_size )
2038-
2039- # make sure the zip file is still valid
2040- with zipfile .ZipFile (TESTFN ) as zh :
2041- self .assertIsNone (zh .testzip ())
2042-
2043- def test_repack_prepended_file_entry (self ):
2044- for ii in ([0 ], [0 , 1 ], [0 , 1 , 2 ]):
2045- with self .subTest (remove = ii ):
2046- # calculate the expected results
2047- fz = io .BytesIO ()
2048- test_files = [data for j , data in enumerate (self .test_files ) if j not in ii ]
2049- self ._prepare_zip_from_test_files (fz , test_files )
2050- fz .seek (0 )
2051- with open (TESTFN , 'wb' ) as fh :
2052- fh .write (b'dummy ' )
2053- fh .write (fz .read ())
2054- with zipfile .ZipFile (TESTFN ) as zh :
2055- expected_zinfos = list (zh .infolist ())
2056- expected_size = os .path .getsize (TESTFN )
2057-
2058- # do the removal and check the result
2059- fz = io .BytesIO ()
2060- with zipfile .ZipFile (fz , 'w' ) as zh :
2061- for j , (file , data ) in enumerate (self .test_files ):
2062- if j in ii :
2063- zh .writestr (file , data )
2064- fz .seek (0 )
2065- prefix = fz .read ()
2066-
2067- fz = io .BytesIO ()
2068- test_files = [data for j , data in enumerate (self .test_files ) if j not in ii ]
2069- self ._prepare_zip_from_test_files (fz , test_files )
2070- fz .seek (0 )
2071-
2072- with open (TESTFN , 'wb' ) as fh :
2073- fh .write (b'dummy ' )
2074- fh .write (prefix )
2075- fh .write (fz .read ())
2076-
2077- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
2078- self .assertEqual (zh .data_offset , 6 + len (prefix ))
2079- zh .repack ()
2080- self .assertEqual (zh .data_offset , 6 )
20812026
20822027 # check infolist
20832028 self .assertEqual (
@@ -2267,10 +2212,8 @@ def test_repack_removed_prepended_bytes(self):
22672212 fh .write (b'dummy ' )
22682213 fh .write (fz .read ())
22692214 with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
2270- self .assertEqual (zh .data_offset , 6 )
22712215 zinfos = [zh .remove (self .test_files [i ][0 ]) for i in ii ]
22722216 zh .repack (zinfos )
2273- self .assertEqual (zh .data_offset , 6 )
22742217
22752218 # check infolist
22762219 self .assertEqual (
0 commit comments