@@ -431,6 +431,30 @@ def test_fileobj_from_fdopen(self):
431
431
with gzip .GzipFile (fileobj = f , mode = "w" ) as g :
432
432
pass
433
433
434
+ def test_fileobj_mode (self ):
435
+ gzip .GzipFile (self .filename , "wb" ).close ()
436
+ with open (self .filename , "r+b" ) as f :
437
+ with gzip .GzipFile (fileobj = f , mode = 'r' ) as g :
438
+ self .assertEqual (g .mode , gzip .READ )
439
+ with gzip .GzipFile (fileobj = f , mode = 'w' ) as g :
440
+ self .assertEqual (g .mode , gzip .WRITE )
441
+ with gzip .GzipFile (fileobj = f , mode = 'a' ) as g :
442
+ self .assertEqual (g .mode , gzip .WRITE )
443
+ with gzip .GzipFile (fileobj = f , mode = 'x' ) as g :
444
+ self .assertEqual (g .mode , gzip .WRITE )
445
+ with self .assertRaises (ValueError ):
446
+ gzip .GzipFile (fileobj = f , mode = 'z' )
447
+ for mode in "rb" , "r+b" :
448
+ with open (self .filename , mode ) as f :
449
+ with gzip .GzipFile (fileobj = f ) as g :
450
+ self .assertEqual (g .mode , gzip .READ )
451
+ for mode in "wb" , "ab" , "xb" :
452
+ if "x" in mode :
453
+ support .unlink (self .filename )
454
+ with open (self .filename , mode ) as f :
455
+ with gzip .GzipFile (fileobj = f ) as g :
456
+ self .assertEqual (g .mode , gzip .WRITE )
457
+
434
458
def test_bytes_filename (self ):
435
459
str_filename = self .filename
436
460
try :
0 commit comments