@@ -391,13 +391,17 @@ def test_compresslevel_metadata(self):
391
391
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
392
392
# specifically, discussion of XFL in section 2.3.1
393
393
cases = [
394
- ('fast' , 1 , b'\x04 ' ),
395
- ('best' , 9 , b'\x02 ' ),
396
- ('tradeoff' , 6 , b'\x00 ' ),
394
+ ('fast' , 0 , b'\x04 ' ),
395
+ ('best' , 3 , b'\x02 ' ),
396
+ ('tradeoff' , 2 , b'\x00 ' ),
397
397
]
398
398
xflOffset = 8
399
399
400
400
for (name , level , expectedXflByte ) in cases :
401
+ major , minor , _ , _ , _ = sys .version_info
402
+ if major == 3 and minor <= 7 or major < 3 :
403
+ # Specific xfl bytes introduced in 3.7
404
+ expectedXflByte = b'\x02 '
401
405
with self .subTest (name ):
402
406
fWrite = igzip .IGzipFile (self .filename , 'w' , compresslevel = level )
403
407
with fWrite :
@@ -440,14 +444,24 @@ def test_zero_padded_file(self):
440
444
d = f .read ()
441
445
self .assertEqual (d , data1 * 50 , "Incorrect data in file" )
442
446
447
+ @unittest .skipIf (sys .version_info [0 ] == 3 and sys .version_info [1 ] < 8
448
+ or sys .version_info [0 ] < 3 ,
449
+ reason = "BadGzipFile exception only in version 3.8 or "
450
+ "higher" )
443
451
def test_igzip_BadGzipFile_exception (self ):
444
452
self .assertTrue (issubclass (igzip .BadGzipFile , OSError ))
445
453
446
454
def test_bad_gzip_file (self ):
455
+ major , minor , _ , _ , _ = sys .version_info
456
+ if major == 3 and minor >= 8 or major > 3 :
457
+ error = igzip .BadGzipFile
458
+ else :
459
+ error = OSError
460
+
447
461
with open (self .filename , 'wb' ) as file :
448
462
file .write (data1 * 50 )
449
463
with igzip .IGzipFile (self .filename , 'r' ) as file :
450
- self .assertRaises (igzip . BadGzipFile , file .readlines )
464
+ self .assertRaises (error , file .readlines )
451
465
452
466
def test_non_seekable_file (self ):
453
467
uncompressed = data1 * 50
@@ -518,7 +532,11 @@ def test_fileobj_mode(self):
518
532
if "x" in mode :
519
533
os .unlink (self .filename )
520
534
with open (self .filename , mode ) as f :
521
- with self .assertWarns (FutureWarning ):
535
+ major , minor , _ , _ , _ = sys .version_info
536
+ if major == 3 and minor >= 9 or major > 3 :
537
+ with self .assertWarns (FutureWarning ):
538
+ g = igzip .IGzipFile (fileobj = f )
539
+ else :
522
540
g = igzip .IGzipFile (fileobj = f )
523
541
with g :
524
542
self .assertEqual (g .mode , igzip .WRITE )
@@ -562,7 +580,7 @@ def test_compress(self):
562
580
def test_compress_mtime (self ):
563
581
mtime = 123456789
564
582
for data in [data1 , data2 ]:
565
- for args in [(), (1 ,), (6 ,), (9 ,)]:
583
+ for args in [(), (0 ,), ( 1 ,), (2 ,), (3 ,)]:
566
584
with self .subTest (data = data , args = args ):
567
585
datac = igzip .compress (data , * args , mtime = mtime )
568
586
self .assertEqual (type (datac ), bytes )
0 commit comments