(self, prompt, terminal_input, stdio_encoding=None, *,
expected=None,
stdin_errors='surrogateescape',
stdout_errors='replace')
| 2692 | return lines |
| 2693 | |
| 2694 | def check_input_tty(self, prompt, terminal_input, stdio_encoding=None, *, |
| 2695 | expected=None, |
| 2696 | stdin_errors='surrogateescape', |
| 2697 | stdout_errors='replace'): |
| 2698 | if not sys.stdin.isatty() or not sys.stdout.isatty(): |
| 2699 | self.skipTest("stdin and stdout must be ttys") |
| 2700 | def child(wpipe): |
| 2701 | # Check the error handlers are accounted for |
| 2702 | if stdio_encoding: |
| 2703 | sys.stdin = io.TextIOWrapper(sys.stdin.detach(), |
| 2704 | encoding=stdio_encoding, |
| 2705 | errors=stdin_errors) |
| 2706 | sys.stdout = io.TextIOWrapper(sys.stdout.detach(), |
| 2707 | encoding=stdio_encoding, |
| 2708 | errors=stdout_errors) |
| 2709 | print("tty =", sys.stdin.isatty() and sys.stdout.isatty(), file=wpipe) |
| 2710 | try: |
| 2711 | print(ascii(input(prompt)), file=wpipe) |
| 2712 | except BaseException as e: |
| 2713 | print(ascii(f'{e.__class__.__name__}: {e!s}'), file=wpipe) |
| 2714 | with self.detach_readline(): |
| 2715 | lines = self.run_child(child, terminal_input + b"\r\n") |
| 2716 | # Check we did exercise the GNU readline path |
| 2717 | self.assertIn(lines[0], {'tty = True', 'tty = False'}) |
| 2718 | if lines[0] != 'tty = True': |
| 2719 | self.skipTest("standard IO in should have been a tty") |
| 2720 | input_result = eval(lines[1]) # ascii() -> eval() roundtrip |
| 2721 | if expected is None: |
| 2722 | if stdio_encoding: |
| 2723 | expected = terminal_input.decode(stdio_encoding, 'surrogateescape') |
| 2724 | else: |
| 2725 | expected = terminal_input.decode(sys.stdin.encoding) # what else? |
| 2726 | self.assertEqual(input_result, expected) |
| 2727 | |
| 2728 | @contextlib.contextmanager |
| 2729 | def detach_readline(self): |
no test coverage detected