MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_input_tty

Method check_input_tty

Lib/test/test_builtin.py:2644–2676  ·  view source on GitHub ↗
(self, prompt, terminal_input, stdio_encoding=None, *,
                        expected=None,
                        stdin_errors='surrogateescape',
                        stdout_errors='replace')

Source from the content-addressed store, hash-verified

2642 return lines
2643
2644 def check_input_tty(self, prompt, terminal_input, stdio_encoding=None, *,
2645 expected=None,
2646 stdin_errors='surrogateescape',
2647 stdout_errors='replace'):
2648 if not sys.stdin.isatty() or not sys.stdout.isatty():
2649 self.skipTest("stdin and stdout must be ttys")
2650 def child(wpipe):
2651 # Check the error handlers are accounted for
2652 if stdio_encoding:
2653 sys.stdin = io.TextIOWrapper(sys.stdin.detach(),
2654 encoding=stdio_encoding,
2655 errors=stdin_errors)
2656 sys.stdout = io.TextIOWrapper(sys.stdout.detach(),
2657 encoding=stdio_encoding,
2658 errors=stdout_errors)
2659 print("tty =", sys.stdin.isatty() and sys.stdout.isatty(), file=wpipe)
2660 try:
2661 print(ascii(input(prompt)), file=wpipe)
2662 except BaseException as e:
2663 print(ascii(f'{e.__class__.__name__}: {e!s}'), file=wpipe)
2664 with self.detach_readline():
2665 lines = self.run_child(child, terminal_input + b"\r\n")
2666 # Check we did exercise the GNU readline path
2667 self.assertIn(lines[0], {'tty = True', 'tty = False'})
2668 if lines[0] != 'tty = True':
2669 self.skipTest("standard IO in should have been a tty")
2670 input_result = eval(lines[1]) # ascii() -> eval() roundtrip
2671 if expected is None:
2672 if stdio_encoding:
2673 expected = terminal_input.decode(stdio_encoding, 'surrogateescape')
2674 else:
2675 expected = terminal_input.decode(sys.stdin.encoding) # what else?
2676 self.assertEqual(input_result, expected)
2677
2678 @contextlib.contextmanager
2679 def detach_readline(self):

Calls 8

detach_readlineMethod · 0.95
run_childMethod · 0.95
skipTestMethod · 0.80
assertInMethod · 0.80
evalFunction · 0.50
isattyMethod · 0.45
decodeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected