@@ -2195,12 +2195,15 @@ def test_chmod(self):
21952195class TestInvalidFD (unittest .TestCase ):
21962196 singles = ["fchdir" , "dup" , "fdatasync" , "fstat" ,
21972197 "fstatvfs" , "fsync" , "tcgetpgrp" , "ttyname" ]
2198+ singles_fildes = {"fchdir" , "fdatasync" , "fsync" }
21982199 #singles.append("close")
21992200 #We omit close because it doesn't raise an exception on some platforms
22002201 def get_single (f ):
22012202 def helper (self ):
22022203 if hasattr (os , f ):
22032204 self .check (getattr (os , f ))
2205+ if f in self .singles_fildes :
2206+ self .check_bool (getattr (os , f ))
22042207 return helper
22052208 for f in singles :
22062209 locals ()["test_" + f ] = get_single (f )
@@ -2214,8 +2217,16 @@ def check(self, f, *args, **kwargs):
22142217 self .fail ("%r didn't raise an OSError with a bad file descriptor"
22152218 % f )
22162219
2220+ def check_bool (self , f , * args , ** kwargs ):
2221+ with warnings .catch_warnings ():
2222+ warnings .simplefilter ("error" , RuntimeWarning )
2223+ for fd in False , True :
2224+ with self .assertRaises (RuntimeWarning ):
2225+ f (fd , * args , ** kwargs )
2226+
22172227 def test_fdopen (self ):
22182228 self .check (os .fdopen , encoding = "utf-8" )
2229+ self .check_bool (os .fdopen , encoding = "utf-8" )
22192230
22202231 @unittest .skipUnless (hasattr (os , 'isatty' ), 'test needs os.isatty()' )
22212232 def test_isatty (self ):
@@ -2277,11 +2288,14 @@ def test_fchown(self):
22772288 def test_fpathconf (self ):
22782289 self .check (os .pathconf , "PC_NAME_MAX" )
22792290 self .check (os .fpathconf , "PC_NAME_MAX" )
2291+ self .check_bool (os .pathconf , "PC_NAME_MAX" )
2292+ self .check_bool (os .fpathconf , "PC_NAME_MAX" )
22802293
22812294 @unittest .skipUnless (hasattr (os , 'ftruncate' ), 'test needs os.ftruncate()' )
22822295 def test_ftruncate (self ):
22832296 self .check (os .truncate , 0 )
22842297 self .check (os .ftruncate , 0 )
2298+ self .check_bool (os .truncate , 0 )
22852299
22862300 @unittest .skipUnless (hasattr (os , 'lseek' ), 'test needs os.lseek()' )
22872301 def test_lseek (self ):
0 commit comments