Skip to content

Commit

Permalink
pythongh-117389: Fix test_compileall.EncodingTest
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Mar 30, 2024
1 parent bfc57d4 commit e4ca0cc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,19 @@ def setUp(self):
self.directory = tempfile.mkdtemp()
self.source_path = os.path.join(self.directory, '_test.py')
with open(self.source_path, 'w', encoding='utf-8') as file:
file.write('# -*- coding: utf-8 -*-\n')
file.write('print u"\u20ac"\n')
file.write('print(b"\u20ac")\n') # intentional error

def tearDown(self):
shutil.rmtree(self.directory)

def test_error(self):
try:
orig_stdout = sys.stdout
sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
compileall.compile_dir(self.directory)
finally:
sys.stdout = orig_stdout
buffer = io.StringIO()
with contextlib.redirect_stdout(buffer):
compiled = compileall.compile_dir(self.directory))
self.assertFalse(compiled) # should not be successful
res = buffer.getvalue()
self.assertIn('SyntaxError', res)
self.assertIn('print(b"€")', res)


class CommandLineTestsBase:
Expand Down

0 comments on commit e4ca0cc

Please sign in to comment.