| 442 | self.assertEqual(out1, out2) |
| 443 | |
| 444 | def test_displayhook_unencodable(self): |
| 445 | for encoding in ('ascii', 'latin-1', 'utf-8'): |
| 446 | env = os.environ.copy() |
| 447 | env['PYTHONIOENCODING'] = encoding |
| 448 | p = subprocess.Popen( |
| 449 | [sys.executable, '-i'], |
| 450 | stdin=subprocess.PIPE, |
| 451 | stdout=subprocess.PIPE, |
| 452 | stderr=subprocess.STDOUT, |
| 453 | env=env) |
| 454 | # non-ascii, surrogate, non-BMP printable, non-BMP unprintable |
| 455 | text = "a=\xe9 b=\uDC80 c=\U00010000 d=\U0010FFFF" |
| 456 | p.stdin.write(ascii(text).encode('ascii') + b"\n") |
| 457 | p.stdin.write(b'exit()\n') |
| 458 | data = kill_python(p) |
| 459 | escaped = repr(text).encode(encoding, 'backslashreplace') |
| 460 | self.assertIn(escaped, data) |
| 461 | |
| 462 | def check_input(self, code, expected): |
| 463 | with tempfile.NamedTemporaryFile("wb+") as stdin: |