@@ -31,7 +31,7 @@ def test_is_writable(self):
3131
3232    def  test_open_w (self ):
3333        p  =  self .root  /  'fileA' 
34-         with  magic_open (p , 'w' ) as  f :
34+         with  magic_open (p , 'w' ,  encoding = 'utf-8' ) as  f :
3535            self .assertIsInstance (f , io .TextIOBase )
3636            f .write ('this is file A\n ' )
3737        self .assertEqual (self .ground .readtext (p ), 'this is file A\n ' )
@@ -70,7 +70,7 @@ def test_write_text(self):
7070        p .write_text ('äbcdefg' , encoding = 'latin-1' )
7171        self .assertEqual (self .ground .readbytes (p ), b'\xe4 bcdefg' )
7272        # Check that trying to write bytes does not truncate the file. 
73-         self .assertRaises (TypeError , p .write_text , b'somebytes' )
73+         self .assertRaises (TypeError , p .write_text , b'somebytes' ,  encoding = 'utf-8' )
7474        self .assertEqual (self .ground .readbytes (p ), b'\xe4 bcdefg' )
7575
7676    @unittest .skipIf ( 
@@ -86,23 +86,23 @@ def test_write_text_encoding_warning(self):
8686    def  test_write_text_with_newlines (self ):
8787        # Check that `\n` character change nothing 
8888        p  =  self .root  /  'fileA' 
89-         p .write_text ('abcde\r \n fghlk\n \r mnopq' , newline = '\n ' )
89+         p .write_text ('abcde\r \n fghlk\n \r mnopq' , encoding = 'utf-8' ,  newline = '\n ' )
9090        self .assertEqual (self .ground .readbytes (p ), b'abcde\r \n fghlk\n \r mnopq' )
9191
9292        # Check that `\r` character replaces `\n` 
9393        p  =  self .root  /  'fileB' 
94-         p .write_text ('abcde\r \n fghlk\n \r mnopq' , newline = '\r ' )
94+         p .write_text ('abcde\r \n fghlk\n \r mnopq' , encoding = 'utf-8' ,  newline = '\r ' )
9595        self .assertEqual (self .ground .readbytes (p ), b'abcde\r \r fghlk\r \r mnopq' )
9696
9797        # Check that `\r\n` character replaces `\n` 
9898        p  =  self .root  /  'fileC' 
99-         p .write_text ('abcde\r \n fghlk\n \r mnopq' , newline = '\r \n ' )
99+         p .write_text ('abcde\r \n fghlk\n \r mnopq' , encoding = 'utf-8' ,  newline = '\r \n ' )
100100        self .assertEqual (self .ground .readbytes (p ), b'abcde\r \r \n fghlk\r \n \r mnopq' )
101101
102102        # Check that no argument passed will change `\n` to `os.linesep` 
103103        os_linesep_byte  =  bytes (os .linesep , encoding = 'ascii' )
104104        p  =  self .root  /  'fileD' 
105-         p .write_text ('abcde\n fghlk\n \r mnopq' )
105+         p .write_text ('abcde\n fghlk\n \r mnopq' ,  encoding = 'utf-8' )
106106        self .assertEqual (self .ground .readbytes (p ),
107107                         b'abcde'  +  os_linesep_byte  + 
108108                         b'fghlk'  +  os_linesep_byte  +  b'\r mnopq' )
0 commit comments