@@ -31,7 +31,7 @@ def test_is_writable(self):
31
31
32
32
def test_open_w (self ):
33
33
p = self .root / 'fileA'
34
- with magic_open (p , 'w' ) as f :
34
+ with magic_open (p , 'w' , encoding = 'utf-8' ) as f :
35
35
self .assertIsInstance (f , io .TextIOBase )
36
36
f .write ('this is file A\n ' )
37
37
self .assertEqual (self .ground .readtext (p ), 'this is file A\n ' )
@@ -70,7 +70,7 @@ def test_write_text(self):
70
70
p .write_text ('äbcdefg' , encoding = 'latin-1' )
71
71
self .assertEqual (self .ground .readbytes (p ), b'\xe4 bcdefg' )
72
72
# 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' )
74
74
self .assertEqual (self .ground .readbytes (p ), b'\xe4 bcdefg' )
75
75
76
76
@unittest .skipIf (
@@ -86,23 +86,23 @@ def test_write_text_encoding_warning(self):
86
86
def test_write_text_with_newlines (self ):
87
87
# Check that `\n` character change nothing
88
88
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 ' )
90
90
self .assertEqual (self .ground .readbytes (p ), b'abcde\r \n fghlk\n \r mnopq' )
91
91
92
92
# Check that `\r` character replaces `\n`
93
93
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 ' )
95
95
self .assertEqual (self .ground .readbytes (p ), b'abcde\r \r fghlk\r \r mnopq' )
96
96
97
97
# Check that `\r\n` character replaces `\n`
98
98
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 ' )
100
100
self .assertEqual (self .ground .readbytes (p ), b'abcde\r \r \n fghlk\r \n \r mnopq' )
101
101
102
102
# Check that no argument passed will change `\n` to `os.linesep`
103
103
os_linesep_byte = bytes (os .linesep , encoding = 'ascii' )
104
104
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' )
106
106
self .assertEqual (self .ground .readbytes (p ),
107
107
b'abcde' + os_linesep_byte +
108
108
b'fghlk' + os_linesep_byte + b'\r mnopq' )
0 commit comments