@@ -3447,8 +3447,8 @@ def test_too_short(self):
3447
3447
self .assertEqual (
3448
3448
b"zzz" , zipfile ._Extra .strip (b"zzz" , (self .ZIP64_EXTRA ,)))
3449
3449
3450
- class StoreSeekReadTest (unittest .TestCase ):
3451
- def test_store_seek_read (self ):
3450
+ class StoredZipExtFileRandomAccessTest (unittest .TestCase ):
3451
+ def test_random_access (self ):
3452
3452
from _pyio import BytesIO
3453
3453
class StatIO (BytesIO ):
3454
3454
def __init__ (self ):
@@ -3464,36 +3464,36 @@ def get_bytes_read(self):
3464
3464
return self .bytes_read
3465
3465
3466
3466
sio = StatIO ()
3467
+ # 100000 bytes
3467
3468
txt = b'0123456789' * 10000
3468
3469
3469
3470
# Check seek on a file
3470
- with zipfile .ZipFile (sio , "w" ) as zipf :
3471
- zipf .writestr ("foo.txt" , txt ) # 100000 bytes
3471
+ with zipfile .ZipFile (sio , "w" , compression = zipfile . ZIP_STORED ) as zipf :
3472
+ zipf .writestr ("foo.txt" , txt )
3472
3473
3473
3474
with zipfile .ZipFile (sio , "r" ) as zipf :
3474
3475
with zipf .open ("foo.txt" , "r" ) as fp :
3475
3476
br = sio .get_bytes_read ()
3476
3477
fp .seek (50000 , os .SEEK_CUR )
3477
- self .assertEqual (sio .get_bytes_read () - br , 0 , 'seek produces extra read!' )
3478
+ self .assertEqual (sio .get_bytes_read () - br , 0 , 'seek produces redundant read!' )
3478
3479
3479
3480
b = fp .read (100 )
3480
3481
self .assertEqual (b , txt [:100 ])
3481
3482
3483
+ # seek length must be greater than ZipExtFile.MIN_READ_SIZE (4096)
3482
3484
# backward seek
3483
- # seek length must be more than MIN_READ_SIZE (4096)
3484
3485
br = sio .get_bytes_read ()
3485
3486
fp .seek (5000 , os .SEEK_CUR )
3486
3487
b = fp .read (100 )
3487
3488
self .assertEqual (b , txt [50000 :50100 ])
3488
- self .assertLessEqual (sio .get_bytes_read () - br , 4096 , 'read more bytes after backward seek!' )
3489
+ self .assertLessEqual (sio .get_bytes_read () - br , 4096 , 'read redundant bytes during backward seek!' )
3489
3490
3490
3491
# forward seek
3491
- # seek length must be more than MIN_READ_SIZE (4096)
3492
3492
br = sio .get_bytes_read ()
3493
3493
fp .seek (- 40000 , os .SEEK_CUR )
3494
3494
b = fp .read (100 )
3495
3495
self .assertEqual (b , txt [10100 :10200 ])
3496
- self .assertLessEqual (sio .get_bytes_read () - br , 4096 , 'read more bytes after forward seek!' )
3496
+ self .assertLessEqual (sio .get_bytes_read () - br , 4096 , 'read redundant bytes during forward seek!' )
3497
3497
3498
3498
if __name__ == "__main__" :
3499
3499
unittest .main ()
0 commit comments