File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -502,19 +502,19 @@ def setUp(self):
502
502
self .directory = tempfile .mkdtemp ()
503
503
self .source_path = os .path .join (self .directory , '_test.py' )
504
504
with open (self .source_path , 'w' , encoding = 'utf-8' ) as file :
505
- file .write ('# -*- coding: utf-8 -*-\n ' )
506
- file .write ('print u"\u20ac "\n ' )
505
+ file .write ('print(b"\u20ac ")\n ' ) # intentional error
507
506
508
507
def tearDown (self ):
509
508
shutil .rmtree (self .directory )
510
509
511
510
def test_error (self ):
512
- try :
513
- orig_stdout = sys .stdout
514
- sys .stdout = io .TextIOWrapper (io .BytesIO (),encoding = 'ascii' )
515
- compileall .compile_dir (self .directory )
516
- finally :
517
- sys .stdout = orig_stdout
511
+ buffer = io .StringIO ()
512
+ with contextlib .redirect_stdout (buffer ):
513
+ compiled = compileall .compile_dir (self .directory ))
514
+ self .assertFalse (compiled ) # should not be successful
515
+ res = buffer .getvalue ()
516
+ self .assertIn ('SyntaxError' , res )
517
+ self .assertIn ('print(b"€")' , res )
518
518
519
519
520
520
class CommandLineTestsBase :
You can’t perform that action at this time.
0 commit comments