@@ -109,7 +109,8 @@ def test_outputs_error_string(self):
109
109
except Exception :
110
110
err_tuple = sys .exc_info ()
111
111
expected = str (err_tuple [1 ]) + '\n '
112
- stdout = StringIO ()
112
+ bytestream = BytesIO ()
113
+ stdout = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
113
114
stdin = StringIO ()
114
115
stderr = StringIO ()
115
116
ui = cli .UI ([], stdin , stdout , stderr )
@@ -128,6 +129,9 @@ def test_error_enters_pdb_when_TESTR_PDB_set(self):
128
129
<BLANKLINE>
129
130
fooo
130
131
""" )
132
+ # This should be a BytesIO + Textwrapper, but pdb on 2.7 writes bytes
133
+ # - this code is the most pragmatic to test on 2.6 and up, and 3.2 and
134
+ # up.
131
135
stdout = StringIO ()
132
136
stdin = StringIO (_u ('c\n ' ))
133
137
stderr = StringIO ()
@@ -196,7 +200,8 @@ def test_outputs_summary_to_stdout(self):
196
200
ui ._stdout .buffer .getvalue ())
197
201
198
202
def test_parse_error_goes_to_stderr (self ):
199
- stdout = StringIO ()
203
+ bytestream = BytesIO ()
204
+ stdout = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
200
205
stdin = StringIO ()
201
206
stderr = StringIO ()
202
207
ui = cli .UI (['one' ], stdin , stdout , stderr )
@@ -206,7 +211,8 @@ def test_parse_error_goes_to_stderr(self):
206
211
self .assertEqual ("Could not find command 'one'.\n " , stderr .getvalue ())
207
212
208
213
def test_parse_excess_goes_to_stderr (self ):
209
- stdout = StringIO ()
214
+ bytestream = BytesIO ()
215
+ stdout = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
210
216
stdin = StringIO ()
211
217
stderr = StringIO ()
212
218
ui = cli .UI (['one' ], stdin , stdout , stderr )
@@ -248,7 +254,8 @@ def test_run_subunit_option(self):
248
254
self .assertEqual (True , ui .options .subunit )
249
255
250
256
def test_dash_dash_help_shows_help (self ):
251
- stdout = StringIO ()
257
+ bytestream = BytesIO ()
258
+ stdout = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
252
259
stdin = StringIO ()
253
260
stderr = StringIO ()
254
261
ui = cli .UI (['--help' ], stdin , stdout , stderr )
@@ -263,7 +270,7 @@ def test_dash_dash_help_shows_help(self):
263
270
self .assertThat (exc_info , MatchesException (SystemExit (0 )))
264
271
else :
265
272
self .fail ('ui.set_command did not raise' )
266
- self .assertThat (stdout .getvalue (),
273
+ self .assertThat (bytestream .getvalue (). decode ( 'utf8' ),
267
274
DocTestMatches ("""Usage: run.py bar [options] foo
268
275
...
269
276
A command that can be run...
@@ -352,9 +359,11 @@ def make_result(self, stream=None, argv=None, filter_tags=None):
352
359
def test_initial_stream (self ):
353
360
# CLITestResult.__init__ does not do anything to the stream it is
354
361
# given.
355
- stream = StringIO ()
356
- cli .CLITestResult (cli .UI (None , None , None , None ), stream , lambda : None )
357
- self .assertEqual ('' , stream .getvalue ())
362
+ bytestream = BytesIO ()
363
+ stream = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
364
+ ui = cli .UI (None , None , None , None )
365
+ cli .CLITestResult (ui , stream , lambda : None )
366
+ self .assertEqual (_b ('' ), bytestream .getvalue ())
358
367
359
368
def test_format_error (self ):
360
369
# CLITestResult formats errors by giving them a big fat line, a title
@@ -376,7 +385,8 @@ def test_format_error_includes_tags(self):
376
385
def test_addFail_outputs_error (self ):
377
386
# CLITestResult.status test_status='fail' outputs the given error
378
387
# immediately to the stream.
379
- stream = StringIO ()
388
+ bytestream = BytesIO ()
389
+ stream = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
380
390
result = self .make_result (stream )[0 ]
381
391
error = self .make_exc_info ()
382
392
error_text = 'foo\n bar\n '
@@ -385,7 +395,7 @@ def test_addFail_outputs_error(self):
385
395
file_name = 'traceback' , mime_type = 'text/plain;charset=utf8' ,
386
396
file_bytes = error_text .encode ('utf8' ))
387
397
self .assertThat (
388
- stream .getvalue (),
398
+ bytestream .getvalue (). decode ( 'utf8' ),
389
399
DocTestMatches (result ._format_error ('FAIL' , self , error_text )))
390
400
391
401
def test_addFailure_handles_string_encoding (self ):
@@ -412,7 +422,8 @@ def test_subunit_output(self):
412
422
self .assertEqual (b'' , bytestream .getvalue ())
413
423
414
424
def test_make_result_tag_filter (self ):
415
- stream = StringIO ()
425
+ bytestream = BytesIO ()
426
+ stream = TextIOWrapper (bytestream , 'utf8' , line_buffering = True )
416
427
result , summary = self .make_result (
417
428
stream , filter_tags = set (['worker-0' ]))
418
429
# Generate a bunch of results with tags in the same events that
@@ -438,5 +449,5 @@ def test_make_result_tag_filter(self):
438
449
----------------------------------------------------------------------
439
450
Ran 1 tests
440
451
FAILED (id=None, failures=1, skips=1)
441
- """ , stream .getvalue ())
452
+ """ , bytestream .getvalue (). decode ( 'utf8' ))
442
453
0 commit comments