(
self,
*,
incoming,
simulate_send_failure=False,
simulate_sigint_during_stdout_write=False,
use_interrupt_socket=False,
expected_outgoing=None,
expected_outgoing_signals=None,
expected_completions=None,
expected_exception=None,
expected_stdout="",
expected_stdout_substring="",
expected_state=None,
)
| 80 | """Tests for the _PdbClient class.""" |
| 81 | |
| 82 | def do_test( |
| 83 | self, |
| 84 | *, |
| 85 | incoming, |
| 86 | simulate_send_failure=False, |
| 87 | simulate_sigint_during_stdout_write=False, |
| 88 | use_interrupt_socket=False, |
| 89 | expected_outgoing=None, |
| 90 | expected_outgoing_signals=None, |
| 91 | expected_completions=None, |
| 92 | expected_exception=None, |
| 93 | expected_stdout="", |
| 94 | expected_stdout_substring="", |
| 95 | expected_state=None, |
| 96 | ): |
| 97 | if expected_outgoing is None: |
| 98 | expected_outgoing = [] |
| 99 | if expected_outgoing_signals is None: |
| 100 | expected_outgoing_signals = [] |
| 101 | if expected_completions is None: |
| 102 | expected_completions = [] |
| 103 | if expected_state is None: |
| 104 | expected_state = {} |
| 105 | |
| 106 | expected_state.setdefault("write_failed", False) |
| 107 | messages = [m for source, m in incoming if source == "server"] |
| 108 | prompts = [m["prompt"] for source, m in incoming if source == "user"] |
| 109 | |
| 110 | input_iter = (m for source, m in incoming if source == "user") |
| 111 | completions = [] |
| 112 | |
| 113 | def mock_input(prompt): |
| 114 | message = next(input_iter, None) |
| 115 | if message is None: |
| 116 | raise EOFError |
| 117 | |
| 118 | if req := message.get("completion_request"): |
| 119 | readline_mock = unittest.mock.Mock() |
| 120 | readline_mock.get_line_buffer.return_value = req["line"] |
| 121 | readline_mock.get_begidx.return_value = req["begidx"] |
| 122 | readline_mock.get_endidx.return_value = req["endidx"] |
| 123 | unittest.mock.seal(readline_mock) |
| 124 | with unittest.mock.patch.dict(sys.modules, {"readline": readline_mock}): |
| 125 | for param in itertools.count(): |
| 126 | prefix = req["line"][req["begidx"] : req["endidx"]] |
| 127 | completion = client.complete(prefix, param) |
| 128 | if completion is None: |
| 129 | break |
| 130 | completions.append(completion) |
| 131 | |
| 132 | reply = message["input"] |
| 133 | if isinstance(reply, BaseException): |
| 134 | raise reply |
| 135 | if isinstance(reply, str): |
| 136 | return reply |
| 137 | return reply() |
| 138 | |
| 139 | with ExitStack() as stack: |
no test coverage detected