Skip to content

Commit 9fd1bb2

Browse files
Try to disable colorization.
1 parent 3ab168a commit 9fd1bb2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Lib/test/test_source_encoding.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4-
from test.support import script_helper, captured_stdout, requires_subprocess, requires_resource
4+
from test import support
5+
from test.support import script_helper
56
from test.support.os_helper import TESTFN, unlink, rmtree
67
from test.support.import_helper import unload
78
import importlib
@@ -64,7 +65,7 @@ def test_issue7820(self):
6465
# two bytes in common with the UTF-8 BOM
6566
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
6667

67-
@requires_subprocess()
68+
@support.requires_subprocess()
6869
def test_20731(self):
6970
sub = subprocess.Popen([sys.executable,
7071
os.path.join(os.path.dirname(__file__),
@@ -270,13 +271,13 @@ def test_second_non_utf8_coding_line(self):
270271
def test_first_utf8_coding_line_error(self):
271272
src = (b'#coding:ascii \xc3\xa4\n'
272273
b'raise RuntimeError\n')
273-
self.check_script_error(src, br"'ascii' codec can't decode byte")
274+
self.check_script_error(src, br"(\(unicode error\) )?'ascii' codec can't decode byte")
274275

275276
def test_second_utf8_coding_line_error(self):
276277
src = (b'#!/usr/bin/python\n'
277278
b'#coding:ascii \xc3\xa4\n'
278279
b'raise RuntimeError\n')
279-
self.check_script_error(src, br"'ascii' codec can't decode byte")
280+
self.check_script_error(src, br"(\(unicode error\) )?'ascii' codec can't decode byte")
280281

281282
def test_utf8_bom(self):
282283
src = (b'\xef\xbb\xbfprint(ascii("\xc3\xa4"))\n')
@@ -318,7 +319,7 @@ def test_utf8_shebang_error(self):
318319
src = (b'#!/home/\xc3\xa4/bin/python\n'
319320
b'#coding:ascii\n'
320321
b'raise RuntimeError\n')
321-
self.check_script_error(src, br"'ascii' codec can't decode byte")
322+
self.check_script_error(src, br"(\(unicode error\) )?'ascii' codec can't decode byte")
322323

323324
def test_non_utf8_shebang_error(self):
324325
src = (b'#!/home/\xa4/bin/python\n'
@@ -407,7 +408,7 @@ def test_nul_in_second_coding_line(self):
407408
class UTF8ValidatorTest(unittest.TestCase):
408409
@unittest.skipIf(not sys.platform.startswith("linux"),
409410
"Too slow to run on non-Linux platforms")
410-
@requires_resource('cpu')
411+
@support.requires_resource('cpu')
411412
def test_invalid_utf8(self):
412413
# This is a port of test_utf8_decode_invalid_sequences in
413414
# test_unicode.py to exercise the separate utf8 validator in
@@ -473,10 +474,11 @@ def check(content):
473474
check(b'\xF4'+cb+b'\xBF\xBF')
474475

475476

477+
@support.force_not_colorized_test_class
476478
class BytesSourceEncodingTest(AbstractSourceEncodingTest, unittest.TestCase):
477479

478480
def check_script_output(self, src, expected):
479-
with captured_stdout() as stdout:
481+
with support.captured_stdout() as stdout:
480482
exec(src)
481483
out = stdout.getvalue().encode('latin1')
482484
self.assertEqual(out.rstrip(), expected)
@@ -494,6 +496,7 @@ def check_script_error(self, src, expected, lineno=...):
494496
self.assertEqual(line, exc.text)
495497

496498

499+
@support.force_not_colorized_test_class
497500
class FileSourceEncodingTest(AbstractSourceEncodingTest, unittest.TestCase):
498501

499502
def check_script_output(self, src, expected):
@@ -511,7 +514,7 @@ def check_script_error(self, src, expected, lineno=...):
511514
fp.write(src)
512515
res = script_helper.assert_python_failure(fn)
513516
err = res.err.rstrip()
514-
self.assertRegex(err.splitlines()[-1], b'SyntaxError.*?' + expected)
517+
self.assertRegex(err.splitlines()[-1], b'SyntaxError: ' + expected)
515518
if lineno is not ...:
516519
self.assertIn(f', line {lineno}\n'.encode(), err)
517520
line = src.splitlines()[lineno-1].decode(errors='replace')

0 commit comments

Comments
 (0)