8000 gh-131591: Add tests for _PdbClient by godlygeek · Pull Request #132976 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-131591: Add tests for _PdbClient #132976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments
  • Loading branch information
godlygeek committed Apr 29, 2025
commit dd1bdab5206d5d7969d243e9007075d41c085112
67 changes: 33 additions & 34 deletions Lib/test/test_remote_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def do_test(
self,
*,
incoming,
simulate_write_failure=False,
simulate_flush_failure=False,
simulate_failure=None,
expected_outgoing=[],
expected_completions=[],
expected_exception=None,
Expand All @@ -141,12 +140,12 @@ def do_test(
sockfile = MockDebuggerSocket(messages)
stdout = io.StringIO()

if simulate_write_failure or simulate_flush_failure:
if simulate_failure:
sockfile.write = unittest.mock.Mock()
sockfile.flush = unittest.mock.Mock()
if simulate_write_failure:
if simulate_failure == "write":
sockfile.write.side_effect = OSError("write failed")
else:
elif simulate_failure == "flush":
sockfile.flush.side_effect = OSError("flush failed")

input_iter = (m for source, m in incoming if source == "user")
Expand Down Expand Up @@ -196,7 +195,7 @@ def mock_input(prompt):
client.cmdloop()

actual_outgoing = sockfile.outgoing
if simulate_write_failure or simulate_flush_failure:
if simulate_failure:
actual_outgoing += [
json.loads(msg.args[0]) for msg in sockfile.write.mock_calls
]
Expand Down Expand Up @@ -304,8 +303,8 @@ def test_handling_pdb_prompts(self):
incoming = [
("server", {"command_list": ["b"]}),
("server", {"prompt": "(Pdb) ", "state": "pdb"}),
("user", {"prompt": "(Pdb) ", "input": "blah ["}),
("user", {"prompt": "... ", "input": "blah ]"}),
("user", {"prompt": "(Pdb) ", "input": "lst ["}),
("user", {"prompt": "... ", "input": "0 ]"}),
("server", {"prompt": "(Pdb) ", "state": "pdb"}),
("user", {"prompt": "(Pdb) ", "input": ""}),
("server", {"prompt": "(Pdb) ", "state": "pdb"}),
Expand All @@ -317,7 +316,7 @@ def test_handling_pdb_prompts(self):
self.do_test(
incoming=incoming,
expected_outgoing=[
{"reply": "blah [\nblah ]"},
{"reply": "lst [\n0 ]"},
{"reply": ""},
{"reply": "b ["},
{"reply": "!b [\nb ]"},
Expand All @@ -330,8 +329,8 @@ def test_handling_interact_prompts(self):
incoming = [
("server", {"command_list": ["b"]}),
("server", {"prompt": ">>> ", "state": "interact"}),
("user", {"prompt": ">>> ", "input": "blah ["}),
("user", {"prompt": "... ", "input": "blah ]"}),
("user", {"prompt": ">>> ", "input": "lst ["}),
("user", {"prompt": "... ", "input": "0 ]"}),
("server", {"prompt": ">>> ", "state": "interact"}),
("user", {"prompt": ">>> ", "input": ""}),
("server", {"prompt": ">>> ", "state": "interact"}),
Expand All @@ -341,7 +340,7 @@ def test_handling_interact_prompts(self):
self.do_test(
incoming=incoming,
expected_outgoing=[
{"reply": "blah [\nblah ]"},
{"reply": "lst [\n0 ]"},
{"reply": ""},
{"reply": "b [\nb ]"},
],
Expand All @@ -352,14 +351,14 @@ def test_retry_pdb_prompt_on_syntax_error(self):
"""Test re-prompting after a SyntaxError in a Python expression."""
incoming = [
("server", {"prompt": "(Pdb) ", "state": "pdb"}),
("user", {"prompt": "(Pdb) ", "input": " blah ["}),
("user", {"prompt": "(Pdb) ", "input": "blah ["}),
("user", {"prompt": "... ", "input": " blah ]"}),
("user", {"prompt": "(Pdb) ", "input": " lst ["}),
("user", {"prompt": "(Pdb) ", "input": "lst ["}),
("user", {"prompt": "... ", "input": " 0 ]"}),
]
self.do_test(
incoming=incoming,
expected_outgoing=[
{"reply": "blah [\n blah ]"},
{"reply": "lst [\n 0 ]"},
],
expected_stdout_substring="*** IndentationError",
expected_state={"state": "pdb"},
Expand All @@ -369,14 +368,14 @@ def test_retry_interact_prompt_on_syntax_error(self):
"""Test re-prompting after a SyntaxError in a Python expression."""
incoming = [
("server", {"prompt": ">>> ", "state": "interact"}),
("user", {"prompt": ">>> ", "input": "!blah ["}),
("user", {"prompt": ">>> ", "input": "blah ["}),
("user", {"prompt": "... ", "input": " blah ]"}),
("user", {"prompt": ">>> ", "input": "!lst ["}),
("user", {"prompt": ">>> ", "input": "lst ["}),
("user", {"prompt": "... ", "input": " 0 ]"}),
]
self.do_test(
incoming=incoming,
expected_outgoing=[
{"reply": "blah [\n blah ]"},
{"reply": "lst [\n 0 ]"},
],
expected_stdout_substring="*** SyntaxError",
expected_state={"state": "interact"},
Expand All @@ -385,14 +384,14 @@ def test_retry_interact_prompt_on_syntax_error(self):
def test_handling_unrecognized_prompt_type(self):
"""Test fallback to "dumb" single-line mode for unknown states."""
incoming = [
("server", {"prompt": "$ ", "state": "shell"}),
("user", {"prompt": "$ ", "input": "! ["}),
("server", {"prompt": "$ ", "state": "shell"}),
("user", {"prompt": "$ ", "input": "echo hello"}),
("server", {"prompt": "$ ", "state": "shell"}),
("user", {"prompt": "$ ", "input": ""}),
("server", {"prompt": "$ ", "state": "shell"}),
("user", {"prompt": "$ ", "input": "echo goodbye"}),
("server", {"prompt": "Do it? ", "state": "confirm"}),
("user", {"prompt": "Do it? ", "input": "! ["}),
("server", {"prompt": "Do it? ", "state": "confirm"}),
("user", {"prompt": "Do it? ", "input": "echo hello"}),
("server", {"prompt": "Do it? ", "state": "confirm"}),
("user", {"prompt": "Do it? ", "input": ""}),
("server", {"prompt": "Do it? ", "state": "confirm"}),
("user", {"prompt": "Do it? ", "input": "echo goodbye"}),
]
self.do_test(
incoming=incoming,
Expand Down Expand Up @@ -474,7 +473,7 @@ def test_write_failing(self):
self.do_test(
incoming=incoming,
expected_outgoing=[{"signal": "INT"}],
simulate_write_failure=True,
simulate_failure="write",
expected_state={"write_failed": True},
)

Expand All @@ -487,7 +486,7 @@ def test_flush_failing(self):
self.do_test(
incoming=incoming,
expected_outgoing=[{"signal": "INT"}],
simulate_flush_failure=True,
simulate_failure="flush",
expected_state={"write_failed": True},
)

Expand Down Expand Up @@ -566,11 +565,11 @@ def test_completion_in_unknown_state(self):
"""Test requesting tab completions at an unrecognized prompt."""
incoming = [
("server", {"command_list": ["p"]}),
("server", {"prompt": "$ ", "state": "shell"}),
("server", {"prompt": "Do it? ", "state": "confirm"}),
(
"user",
{
"prompt": "$ ",
"prompt": "Do it? ",
"completion_request": {
"line": "_",
"begidx": 0,
Expand Down Expand Up @@ -618,7 +617,7 @@ def test_write_failure_during_completion(self):
},
{"reply": "xyz"},
],
simulate_write_failure=True,
simulate_failure="write",
expected_completions=[],
expected_state={"state": "interact", "write_failed": True},
)
Expand Down Expand Up @@ -653,7 +652,7 @@ def test_flush_failure_during_completion(self):
},
{"reply": "xyz"},
],
simulate_flush_failure=True,
simulate_failure="flush",
expected_completions=[],
expected_state={"state": "interact", "write_failed": True},
)
Expand Down
Loading
0