mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-117389: Fix test_compileall.EncodingTest
(GH-117390) (#118603)
gh-117389: Fix `test_compileall.EncodingTest` (GH-117390)
(cherry picked from commit 44f67916da
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
68316a04f3
commit
11594da046
1 changed files with 14 additions and 8 deletions
|
@ -477,19 +477,25 @@ class EncodingTest(unittest.TestCase):
|
||||||
self.directory = tempfile.mkdtemp()
|
self.directory = tempfile.mkdtemp()
|
||||||
self.source_path = os.path.join(self.directory, '_test.py')
|
self.source_path = os.path.join(self.directory, '_test.py')
|
||||||
with open(self.source_path, 'w', encoding='utf-8') as file:
|
with open(self.source_path, 'w', encoding='utf-8') as file:
|
||||||
file.write('# -*- coding: utf-8 -*-\n')
|
# Intentional syntax error: bytes can only contain
|
||||||
file.write('print u"\u20ac"\n')
|
# ASCII literal characters.
|
||||||
|
file.write('b"\u20ac"')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.directory)
|
shutil.rmtree(self.directory)
|
||||||
|
|
||||||
def test_error(self):
|
def test_error(self):
|
||||||
try:
|
buffer = io.TextIOWrapper(io.BytesIO(), encoding='ascii')
|
||||||
orig_stdout = sys.stdout
|
with contextlib.redirect_stdout(buffer):
|
||||||
sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
|
compiled = compileall.compile_dir(self.directory)
|
||||||
compileall.compile_dir(self.directory)
|
self.assertFalse(compiled) # should not be successful
|
||||||
finally:
|
buffer.seek(0)
|
||||||
sys.stdout = orig_stdout
|
res = buffer.read()
|
||||||
|
self.assertIn(
|
||||||
|
'SyntaxError: bytes can only contain ASCII literal characters',
|
||||||
|
res,
|
||||||
|
)
|
||||||
|
self.assertNotIn('UnicodeEncodeError', res)
|
||||||
|
|
||||||
|
|
||||||
class CommandLineTestsBase:
|
class CommandLineTestsBase:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue