@@ -269,7 +269,7 @@ def test_write_windows_console(self):
269
269
270
270
def fdopen_helper (self , * args ):
271
271
fd = os .open (os_helper .TESTFN , os .O_RDONLY )
272
- f = os .fdopen (fd , * args )
272
+ f = os .fdopen (fd , * args , encoding = "utf-8" )
273
273
f .close ()
274
274
275
275
def test_fdopen (self ):
@@ -290,7 +290,7 @@ def test_replace(self):
290
290
291
291
os .replace (os_helper .TESTFN , TESTFN2 )
292
292
self .assertRaises (FileNotFoundError , os .stat , os_helper .TESTFN )
293
- with open (TESTFN2 , 'r' ) as f :
293
+ with open (TESTFN2 , 'r' , encoding = 'utf-8' ) as f :
294
294
self .assertEqual (f .read (), "1" )
295
295
296
296
def test_open_keywords (self ):
@@ -1627,7 +1627,7 @@ def test_exist_ok_s_isgid_directory(self):
1627
1627
def test_exist_ok_existing_regular_file (self ):
1628
1628
base = os_helper .TESTFN
1629
1629
path = os .path .join (os_helper .TESTFN , 'dir1' )
1630
- with open (path , 'w' ) as f :
1630
+ with open (path , 'w' , encoding = 'utf-8' ) as f :
1631
1631
f .write ('abc' )
1632
1632
self .assertRaises (OSError , os .makedirs , path )
1633
1633
self .assertRaises (OSError , os .makedirs , path , exist_ok = False )
@@ -2094,7 +2094,7 @@ def test_chmod(self):
2094
2094
2095
2095
2096
2096
class TestInvalidFD (unittest .TestCase ):
2097
- singles = ["fchdir" , "dup" , "fdopen" , " fdatasync" , "fstat" ,
2097
+ singles = ["fchdir" , "dup" , "fdatasync" , "fstat" ,
2098
2098
"fstatvfs" , "fsync" , "tcgetpgrp" , "ttyname" ]
2099
2099
#singles.append("close")
2100
2100
#We omit close because it doesn't raise an exception on some platforms
@@ -2106,15 +2106,18 @@ def helper(self):
2106
2106
for f in singles :
2107
2107
locals ()["test_" + f ] = get_single (f )
2108
2108
2109
- def check (self , f , * args ):
2109
+ def check (self , f , * args , ** kwargs ):
2110
2110
try :
2111
- f (os_helper .make_bad_fd (), * args )
2111
+ f (os_helper .make_bad_fd (), * args , ** kwargs )
2112
2112
except OSError as e :
2113
2113
self .assertEqual (e .errno , errno .EBADF )
2114
2114
else :
2115
2115
self .fail ("%r didn't raise an OSError with a bad file descriptor"
2116
2116
% f )
2117
2117
2118
+ def test_fdopen (self ):
2119
+ self .check (os .fdopen , encoding = "utf-8" )
2120
+
2118
2121
@unittest .skipUnless (hasattr (os , 'isatty' ), 'test needs os.isatty()' )
2119
2122
def test_isatty (self ):
2120
2123
self .assertEqual (os .isatty (os_helper .make_bad_fd ()), False )
@@ -2210,7 +2213,7 @@ def _test_link(self, file1, file2):
2210
2213
os .link (file1 , file2 )
2211
2214
except PermissionError as e :
2212
2215
self .skipTest ('os.link(): %s' % e )
2213
- with open (file1 , "r " ) as f1 , open (file2 , "r " ) as f2 :
2216
+ with open (file1 , "rb " ) as f1 , open (file2 , "rb " ) as f2 :
2214
2217
self .assertTrue (os .path .sameopenfile (f1 .fileno (), f2 .fileno ()))
2215
2218
2216
2219
def test_link (self ):
@@ -3009,7 +3012,7 @@ def create_args(self, *, with_env=False, use_bytes=False):
3009
3012
code = ('import sys, os; magic = os.environ[%r]; sys.exit(%s)'
3010
3013
% (self .key , self .exitcode ))
3011
3014
3012
- with open (filename , "w" ) as fp :
3015
+ with open (filename , "w" , encoding = "utf-8" ) as fp :
3013
3016
fp .write (code )
3014
3017
3015
3018
args = [sys .executable , filename ]
@@ -3149,7 +3152,7 @@ def _test_invalid_env(self, spawn):
3149
3152
# equal character in the environment variable value
3150
3153
filename = os_helper .TESTFN
3151
3154
self .addCleanup (os_helper .unlink , filename )
3152
- with open (filename , "w" ) as fp :
3155
+ with open (filename , "w" , encoding = "utf-8" ) as fp :
3153
3156
fp .write ('import sys, os\n '
3154
3157
'if os.getenv("FRUIT") != "orange=lemon":\n '
3155
3158
' raise AssertionError' )
0 commit comments