@@ -461,40 +461,40 @@ def test_concatenated_gzip():
461
461
462
462
def test_seek ():
463
463
from io import SEEK_CUR , SEEK_END , SEEK_SET
464
- with tempfile .NamedTemporaryFile ("wb" ) as tmpfile :
464
+ with tempfile .NamedTemporaryFile ("wb" , delete = False ) as tmpfile :
465
465
tmpfile .write (gzip .compress (b"X" * 500 + b"A" + b"X" * 499 ))
466
466
tmpfile .write (gzip .compress (b"X" * 500 + b"B" + b"X" * 499 ))
467
467
tmpfile .write (gzip .compress (b"X" * 500 + b"C" + b"X" * 499 ))
468
468
tmpfile .write (gzip .compress (b"X" * 500 + b"D" + b"X" * 499 ))
469
- tmpfile . flush ()
470
- with igzip . open ( tmpfile . name , "rb" ) as gzip_file :
471
- # Start testing forward seek
472
- gzip_file .seek ( 500 )
473
- assert gzip_file .read ( 1 ) == b"A"
474
- gzip_file .seek ( 1500 )
475
- assert gzip_file . read ( 1 ) == b"B"
476
- # Test reverse
477
- gzip_file .seek ( 500 )
478
- assert gzip_file . read ( 1 ) == b"A"
479
- # Again, but with explicit SEEK_SET
480
- gzip_file .seek ( 500 , SEEK_SET )
481
- assert gzip_file .read ( 1 ) == b"A"
482
- gzip_file .seek ( 1500 , SEEK_SET )
483
- assert gzip_file .read ( 1 ) == b"B"
484
- gzip_file .seek ( 500 , SEEK_SET )
485
- assert gzip_file . read ( 1 ) == b"A"
486
- # Seeking from current position
487
- gzip_file .seek (500 )
488
- gzip_file .seek ( 2000 , SEEK_CUR )
489
- assert gzip_file .read ( 1 ) == b"C"
490
- gzip_file .seek ( - 1001 , SEEK_CUR )
491
- assert gzip_file . read ( 1 ) == b"B"
492
- # Seeking from end
493
- # Any positive number should end up at the end
494
- gzip_file .seek ( 200 , SEEK_END )
495
- assert gzip_file .read ( 1 ) == b""
496
- gzip_file .seek ( - 1500 , SEEK_END )
497
- assert gzip_file . read ( 1 ) == b"C"
469
+ with igzip . open ( tmpfile . name , "rb" ) as gzip_file :
470
+ # Start testing forward seek
471
+ gzip_file . seek ( 500 )
472
+ assert gzip_file .read ( 1 ) == b"A"
473
+ gzip_file .seek ( 1500 )
474
+ assert gzip_file .read ( 1 ) == b"B"
475
+ # Test reverse
476
+ gzip_file . seek ( 500 )
477
+ assert gzip_file .read ( 1 ) == b"A"
478
+ # Again, but with explicit SEEK_SET
479
+ gzip_file . seek ( 500 , SEEK_SET )
480
+ assert gzip_file .read ( 1 ) == b"A"
481
+ gzip_file .seek ( 1500 , SEEK_SET )
482
+ assert gzip_file .read ( 1 ) == b"B"
483
+ gzip_file .seek ( 500 , SEEK_SET )
484
+ assert gzip_file .read ( 1 ) == b"A"
485
+ # Seeking from current position
486
+ gzip_file . seek ( 500 )
487
+ gzip_file .seek (2000 , SEEK_CUR )
488
+ assert gzip_file .read ( 1 ) == b"C"
489
+ gzip_file .seek ( - 1001 , SEEK_CUR )
490
+ assert gzip_file .read ( 1 ) == b"B"
491
+ # Seeking from end
492
+ # Any positive number should end up at the end
493
+ gzip_file . seek ( 200 , SEEK_END )
494
+ assert gzip_file .read ( 1 ) == b""
495
+ gzip_file .seek ( - 1500 , SEEK_END )
496
+ assert gzip_file .read ( 1 ) == b"C"
497
+ os . remove ( tmpfile . name )
498
498
499
499
500
500
def test_bgzip ():
0 commit comments