@@ -304,7 +304,7 @@ def testAbles(self):
304304 finally :
305305 os .unlink (TESTFN )
306306
307- def testModeStrings (self ):
307+ def testInvalidModeStrings (self ):
308308 # check invalid mode strings
309309 for mode in ("" , "aU" , "wU+" , "rw" , "rt" ):
310310 try :
@@ -315,6 +315,21 @@ def testModeStrings(self):
315315 f .close ()
316316 self .fail ('%r is an invalid file mode' % mode )
317317
318+ def testModeStrings (self ):
319+ # test that the mode attribute is correct for various mode strings
320+ # given as init args
321+ try :
322+ for modes in [('w' , 'wb' ), ('wb' , 'wb' ), ('wb+' , 'rb+' ),
323+ ('w+b' , 'rb+' ), ('a' , 'ab' ), ('ab' , 'ab' ),
324+ ('ab+' , 'ab+' ), ('a+b' , 'ab+' ), ('r' , 'rb' ),
325+ ('rb' , 'rb' ), ('rb+' , 'rb+' ), ('r+b' , 'rb+' )]:
326+ # read modes are last so that TESTFN will exist first
327+ with _FileIO (TESTFN , modes [0 ]) as f :
328+ self .assertEqual (f .mode , modes [1 ])
329+ finally :
330+ if os .path .exists (TESTFN ):
331+ os .unlink (TESTFN )
332+
318333 def testUnicodeOpen (self ):
319334 # verify repr works for unicode too
320335 f = _FileIO (str (TESTFN ), "w" )
0 commit comments