@@ -3158,6 +3158,10 @@ def test_trace_compressed_block_end_zlib(self):
31583158 def test_trace_compressed_block_end_bz2 (self ):
31593159 self ._test_trace_compressed_block_end (zipfile .ZIP_BZIP2 , OSError )
31603160
3161+ @requires_lzma ()
3162+ def test_trace_compressed_block_end_lzma (self ):
3163+ self ._test_trace_compressed_block_end (zipfile .ZIP_LZMA , EOFError )
3164+
31613165 @requires_zstd ()
31623166 def test_trace_compressed_block_end_zstd (self ):
31633167 import compression .zstd
@@ -3226,6 +3230,86 @@ def _test_trace_compressed_block_end(self, method, exc_cls):
32263230 comp_len ,
32273231 )
32283232
3233+ def test_calc_local_file_entry_size (self ):
3234+ repacker = zipfile ._ZipRepacker ()
3235+
3236+ # basic
3237+ fz = io .BytesIO ()
3238+ with zipfile .ZipFile (fz , 'w' ) as zh :
3239+ with zh .open ('file.txt' , 'w' ) as fh :
3240+ fh .write (b'dummy' )
3241+ zi = zh .infolist ()[- 1 ]
3242+
3243+ self .assertEqual (
3244+ repacker ._calc_local_file_entry_size (fz , zi ),
3245+ 43 ,
3246+ )
3247+
3248+ # data descriptor
3249+ fz = io .BytesIO ()
3250+ with zipfile .ZipFile (Unseekable (fz ), 'w' ) as zh :
3251+ with zh .open ('file.txt' , 'w' ) as fh :
3252+ fh .write (b'dummy' )
3253+ zi = zh .infolist ()[- 1 ]
3254+
3255+ self .assertEqual (
3256+ repacker ._calc_local_file_entry_size (fz , zi ),
3257+ 59 ,
3258+ )
3259+
3260+ # data descriptor (unsigned)
3261+ fz = io .BytesIO ()
3262+ with zipfile .ZipFile (Unseekable (fz ), 'w' ) as zh :
3263+ with mock .patch .object (struct , 'pack' , side_effect = struct_pack_no_dd_sig ), \
3264+ zh .open ('file.txt' , 'w' ) as fh :
3265+ fh .write (b'dummy' )
3266+ zi = zh .infolist ()[- 1 ]
3267+
3268+ self .assertEqual (
3269+ repacker ._calc_local_file_entry_size (fz , zi ),
3270+ 55 ,
3271+ )
3272+
3273+ def test_calc_local_file_entry_size_zip64 (self ):
3274+ repacker = zipfile ._ZipRepacker ()
3275+
3276+ # zip64
3277+ fz = io .BytesIO ()
3278+ with zipfile .ZipFile (fz , 'w' ) as zh :
3279+ with zh .open ('file.txt' , 'w' , force_zip64 = True ) as fh :
3280+ fh .write (b'dummy' )
3281+ zi = zh .infolist ()[- 1 ]
3282+
3283+ self .assertEqual (
3284+ repacker ._calc_local_file_entry_size (fz , zi ),
3285+ 63 ,
3286+ )
3287+
3288+ # data descriptor + zip64
3289+ fz = io .BytesIO ()
3290+ with zipfile .ZipFile (Unseekable (fz ), 'w' ) as zh :
3291+ with zh .open ('file.txt' , 'w' , force_zip64 = True ) as fh :
3292+ fh .write (b'dummy' )
3293+ zi = zh .infolist ()[- 1 ]
3294+
3295+ self .assertEqual (
3296+ repacker ._calc_local_file_entry_size (fz , zi ),
3297+ 87 ,
3298+ )
3299+
3300+ # data descriptor (unsigned) + zip64
3301+ fz = io .BytesIO ()
3302+ with zipfile .ZipFile (Unseekable (fz ), 'w' ) as zh :
3303+ with mock .patch .object (struct , 'pack' , side_effect = struct_pack_no_dd_sig ), \
3304+ zh .open ('file.txt' , 'w' , force_zip64 = True ) as fh :
3305+ fh .write (b'dummy' )
3306+ zi = zh .infolist ()[- 1 ]
3307+
3308+ self .assertEqual (
3309+ repacker ._calc_local_file_entry_size (fz , zi ),
3310+ 83 ,
3311+ )
3312+
32293313 def test_copy_bytes (self ):
32303314 repacker = zipfile ._ZipRepacker ()
32313315
0 commit comments