(self)
| 2033 | output) |
| 2034 | |
| 2035 | def test_worker_decode_error(self): |
| 2036 | # gh-109425: Use "backslashreplace" error handler to decode stdout. |
| 2037 | if sys.platform == 'win32': |
| 2038 | encoding = locale.getencoding() |
| 2039 | else: |
| 2040 | encoding = sys.stdout.encoding |
| 2041 | if encoding is None: |
| 2042 | encoding = sys.__stdout__.encoding |
| 2043 | if encoding is None: |
| 2044 | self.skipTest("cannot get regrtest worker encoding") |
| 2045 | |
| 2046 | nonascii = bytes(ch for ch in range(128, 256)) |
| 2047 | corrupted_output = b"nonascii:%s\n" % (nonascii,) |
| 2048 | # gh-108989: On Windows, assertion errors are written in UTF-16: when |
| 2049 | # decoded each letter is follow by a NUL character. |
| 2050 | assertion_failed = 'Assertion failed: tstate_is_alive(tstate)\n' |
| 2051 | corrupted_output += assertion_failed.encode('utf-16-le') |
| 2052 | try: |
| 2053 | corrupted_output.decode(encoding) |
| 2054 | except UnicodeDecodeError: |
| 2055 | pass |
| 2056 | else: |
| 2057 | self.skipTest(f"{encoding} can decode non-ASCII bytes") |
| 2058 | |
| 2059 | expected_line = corrupted_output.decode(encoding, 'backslashreplace') |
| 2060 | |
| 2061 | code = textwrap.dedent(fr""" |
| 2062 | import sys |
| 2063 | import unittest |
| 2064 | |
| 2065 | class Tests(unittest.TestCase): |
| 2066 | def test_pass(self): |
| 2067 | pass |
| 2068 | |
| 2069 | # bytes which cannot be decoded from UTF-8 |
| 2070 | corrupted_output = {corrupted_output!a} |
| 2071 | sys.stdout.buffer.write(corrupted_output) |
| 2072 | sys.stdout.buffer.flush() |
| 2073 | """) |
| 2074 | testname = self.create_test(code=code) |
| 2075 | |
| 2076 | output = self.run_tests("--fail-env-changed", "-v", "-j1", testname) |
| 2077 | self.check_executed_tests(output, [testname], |
| 2078 | parallel=True, |
| 2079 | stats=1) |
| 2080 | self.check_line(output, expected_line, regex=False) |
| 2081 | |
| 2082 | def test_doctest(self): |
| 2083 | code = textwrap.dedent(r''' |
nothing calls this directly
no test coverage detected