Skip to content

Commit 7b1aa3b

Browse files
committed
Refactor test cases with @SubTests; add test cases for the scenario when help is not available
1 parent a81fd57 commit 7b1aa3b

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

Lib/test/test_remote_pdb.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import unittest
1212
import unittest.mock
1313
from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
14-
from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT
14+
from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT, subTests
1515
from test.support.os_helper import TESTFN, unlink
1616
from typing import List
1717

@@ -279,52 +279,50 @@ def test_handling_other_message(self):
279279
expected_stdout="Some message.\n",
280280
)
281281

282-
@unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO")
283-
def test_handling_help_for_command(self):
284-
"""Test handling a request to display help for a command."""
285-
incoming = [
286-
("server", {"help": "ll"}),
287-
]
288-
self.do_test(
289-
incoming=incoming,
290-
expected_outgoing=[],
291-
expected_stdout_substring="Usage: ll | longlist",
292-
)
293-
294-
@unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO")
295-
def test_handling_help_without_a_specific_topic(self):
296-
"""Test handling a request to display a help overview."""
297-
incoming = [
298-
("server", {"help": ""}),
299-
]
300-
self.do_test(
301-
incoming=incoming,
302-
expected_outgoing=[],
303-
expected_stdout_substring="type help <topic>",
304-
)
305-
306282
@unittest.skipIf(sys.flags.optimize >= 2, "Help not available for -OO")
307-
def test_handling_help_pdb(self):
308-
"""Test handling a request to display the full PDB manual."""
283+
@subTests(
284+
"help_request,expected_substring",
285+
[
286+
# a request to display help for a command
287+
({"help": "ll"}, "Usage: ll | longlist"),
288+
# a request to display a help overview
289+
({"help": ""}, "type help <topic>"),
290+
# a request to display the full PDB manual
291+
({"help": "pdb"}, ">>> import pdb"),
292+
],
293+
)
294+
def test_handling_help_when_available(self, help_request, expected_substring):
295+
"""Test handling help requests when help is available."""
309296
incoming = [
310-
("server", {"help": "pdb"}),
297+
("server", help_request),
311298
]
312299
self.do_test(
313300
incoming=incoming,
314301
expected_outgoing=[],
315-
expected_stdout_substring=">>> import pdb",
302+
expected_stdout_substring=expected_substring,
316303
)
317304

318305
@unittest.skipIf(sys.flags.optimize < 2, "Needs -OO")
319-
def test_handling_no_help_available(self):
320-
"""Test handling a request when no help if available."""
306+
@subTests(
307+
"help_request,expected_substring",
308+
[
309+
# a request to display help for a command
310+
({"help": "ll"}, "No help for 'll'"),
311+
# a request to display a help overview
312+
({"help": ""}, "Undocumented commands"),
313+
# a request to display the full PDB manual
314+
({"help": "pdb"}, "No help for 'pdb'"),
315+
],
316+
)
317+
def test_handling_help_when_not_available(self, help_request, expected_substring):
318+
"""Test handling help requests when help is not available."""
321319
incoming = [
322-
("server", {"help": "pdb"}),
320+
("server", help_request),
323321
]
324322
self.do_test(
325323
incoming=incoming,
326324
expected_outgoing=[],
327-
expected_stdout_substring="No help for 'pdb'",
325+
expected_stdout_substring=expected_substring,
328326
)
329327

330328
def test_handling_pdb_prompts(self):

0 commit comments

Comments
 (0)