@@ -36,7 +36,7 @@ def __eq__(self, other):
3636 self .assertIn ('UnhashableException: ex1' , tb [10 ])
3737
3838
39- # PseudoFile tests.
39+ # StdioFile tests.
4040
4141class S (str ):
4242 def __str__ (self ):
@@ -68,14 +68,14 @@ def push(self, lines):
6868 self .lines = list (lines )[::- 1 ]
6969
7070
71- class PseudeInputFilesTest (unittest .TestCase ):
71+ class StdInputFilesTest (unittest .TestCase ):
7272
7373 def test_misc (self ):
7474 shell = MockShell ()
75- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
75+ f = run .StdInputFile (shell , 'stdin' )
7676 self .assertIsInstance (f , io .TextIOBase )
7777 self .assertEqual (f .encoding , 'utf-8' )
78- self .assertIsNone (f .errors )
78+ self .assertEqual (f .errors , 'strict' )
7979 self .assertIsNone (f .newlines )
8080 self .assertEqual (f .name , '<stdin>' )
8181 self .assertFalse (f .closed )
@@ -86,7 +86,7 @@ def test_misc(self):
8686
8787 def test_unsupported (self ):
8888 shell = MockShell ()
89- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
89+ f = run .StdInputFile (shell , 'stdin' )
9090 self .assertRaises (OSError , f .fileno )
9191 self .assertRaises (OSError , f .tell )
9292 self .assertRaises (OSError , f .seek , 0 )
@@ -95,7 +95,7 @@ def test_unsupported(self):
9595
9696 def test_read (self ):
9797 shell = MockShell ()
98- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
98+ f = run .StdInputFile (shell , 'stdin' )
9999 shell .push (['one\n ' , 'two\n ' , '' ])
100100 self .assertEqual (f .read (), 'one\n two\n ' )
101101 shell .push (['one\n ' , 'two\n ' , '' ])
@@ -115,7 +115,7 @@ def test_read(self):
115115
116116 def test_readline (self ):
117117 shell = MockShell ()
118- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
118+ f = run .StdInputFile (shell , 'stdin' )
119119 shell .push (['one\n ' , 'two\n ' , 'three\n ' , 'four\n ' ])
120120 self .assertEqual (f .readline (), 'one\n ' )
121121 self .assertEqual (f .readline (- 1 ), 'two\n ' )
@@ -140,7 +140,7 @@ def test_readline(self):
140140
141141 def test_readlines (self ):
142142 shell = MockShell ()
143- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
143+ f = run .StdInputFile (shell , 'stdin' )
144144 shell .push (['one\n ' , 'two\n ' , '' ])
145145 self .assertEqual (f .readlines (), ['one\n ' , 'two\n ' ])
146146 shell .push (['one\n ' , 'two\n ' , '' ])
@@ -161,7 +161,7 @@ def test_readlines(self):
161161
162162 def test_close (self ):
163163 shell = MockShell ()
164- f = run .PseudoInputFile (shell , 'stdin' , 'utf-8 ' )
164+ f = run .StdInputFile (shell , 'stdin' )
165165 shell .push (['one\n ' , 'two\n ' , '' ])
166166 self .assertFalse (f .closed )
167167 self .assertEqual (f .readline (), 'one\n ' )
@@ -171,14 +171,14 @@ def test_close(self):
171171 self .assertRaises (TypeError , f .close , 1 )
172172
173173
174- class PseudeOutputFilesTest (unittest .TestCase ):
174+ class StdOutputFilesTest (unittest .TestCase ):
175175
176176 def test_misc (self ):
177177 shell = MockShell ()
178- f = run .PseudoOutputFile (shell , 'stdout' , 'utf-8 ' )
178+ f = run .StdOutputFile (shell , 'stdout' )
179179 self .assertIsInstance (f , io .TextIOBase )
180180 self .assertEqual (f .encoding , 'utf-8' )
181- self .assertIsNone (f .errors )
181+ self .assertEqual (f .errors , 'strict' )
182182 self .assertIsNone (f .newlines )
183183 self .assertEqual (f .name , '<stdout>' )
184184 self .assertFalse (f .closed )
@@ -189,7 +189,7 @@ def test_misc(self):
189189
190190 def test_unsupported (self ):
191191 shell = MockShell ()
192- f = run .PseudoOutputFile (shell , 'stdout' , 'utf-8 ' )
192+ f = run .StdOutputFile (shell , 'stdout' )
193193 self .assertRaises (OSError , f .fileno )
194194 self .assertRaises (OSError , f .tell )
195195 self .assertRaises (OSError , f .seek , 0 )
@@ -198,16 +198,36 @@ def test_unsupported(self):
198198
199199 def test_write (self ):
200200 shell = MockShell ()
201- f = run .PseudoOutputFile (shell , 'stdout' , 'utf-8 ' )
201+ f = run .StdOutputFile (shell , 'stdout' )
202202 f .write ('test' )
203203 self .assertEqual (shell .written , [('test' , 'stdout' )])
204204 shell .reset ()
205- f .write ('t\xe8 st ' )
206- self .assertEqual (shell .written , [('t\xe8 st ' , 'stdout' )])
205+ f .write ('t\xe8 \u015b \U0001d599 ' )
206+ self .assertEqual (shell .written , [('t\xe8 \u015b \U0001d599 ' , 'stdout' )])
207207 shell .reset ()
208208
209- f .write (S ('t\xe8 st' ))
210- self .assertEqual (shell .written , [('t\xe8 st' , 'stdout' )])
209+ f .write (S ('t\xe8 \u015b \U0001d599 ' ))
210+ self .assertEqual (shell .written , [('t\xe8 \u015b \U0001d599 ' , 'stdout' )])
211+ self .assertEqual (type (shell .written [0 ][0 ]), str )
212+ shell .reset ()
213+
214+ self .assertRaises (TypeError , f .write )
215+ self .assertEqual (shell .written , [])
216+ self .assertRaises (TypeError , f .write , b'test' )
217+ self .assertRaises (TypeError , f .write , 123 )
218+ self .assertEqual (shell .written , [])
219+ self .assertRaises (TypeError , f .write , 'test' , 'spam' )
220+ self .assertEqual (shell .written , [])
221+
222+ def test_write_stderr_nonencodable (self ):
223+ shell = MockShell ()
224+ f = run .StdOutputFile (shell , 'stderr' , 'iso-8859-15' , 'backslashreplace' )
225+ f .write ('t\xe8 \u015b \U0001d599 \xa4 ' )
226+ self .assertEqual (shell .written , [('t\xe8 \\ u015b\\ U0001d599\\ xa4' , 'stderr' )])
227+ shell .reset ()
228+
229+ f .write (S ('t\xe8 \u015b \U0001d599 \xa4 ' ))
230+ self .assertEqual (shell .written , [('t\xe8 \\ u015b\\ U0001d599\\ xa4' , 'stderr' )])
211231 self .assertEqual (type (shell .written [0 ][0 ]), str )
212232 shell .reset ()
213233
@@ -221,7 +241,7 @@ def test_write(self):
221241
222242 def test_writelines (self ):
223243 shell = MockShell ()
224- f = run .PseudoOutputFile (shell , 'stdout' , 'utf-8 ' )
244+ f = run .StdOutputFile (shell , 'stdout' )
225245 f .writelines ([])
226246 self .assertEqual (shell .written , [])
227247 shell .reset ()
@@ -251,7 +271,7 @@ def test_writelines(self):
251271
252272 def test_close (self ):
253273 shell = MockShell ()
254- f = run .PseudoOutputFile (shell , 'stdout' , 'utf-8 ' )
274+ f = run .StdOutputFile (shell , 'stdout' )
255275 self .assertFalse (f .closed )
256276 f .write ('test' )
257277 f .close ()
0 commit comments