|
11 | 11 | import unittest |
12 | 12 | import unittest.mock |
13 | 13 | 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 |
15 | 15 | from test.support.os_helper import TESTFN, unlink |
16 | 16 | from typing import List |
17 | 17 |
|
@@ -279,52 +279,50 @@ def test_handling_other_message(self): |
279 | 279 | expected_stdout="Some message.\n", |
280 | 280 | ) |
281 | 281 |
|
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 | | - |
306 | 282 | @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.""" |
309 | 296 | incoming = [ |
310 | | - ("server", {"help": "pdb"}), |
| 297 | + ("server", help_request), |
311 | 298 | ] |
312 | 299 | self.do_test( |
313 | 300 | incoming=incoming, |
314 | 301 | expected_outgoing=[], |
315 | | - expected_stdout_substring=">>> import pdb", |
| 302 | + expected_stdout_substring=expected_substring, |
316 | 303 | ) |
317 | 304 |
|
318 | 305 | @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.""" |
321 | 319 | incoming = [ |
322 | | - ("server", {"help": "pdb"}), |
| 320 | + ("server", help_request), |
323 | 321 | ] |
324 | 322 | self.do_test( |
325 | 323 | incoming=incoming, |
326 | 324 | expected_outgoing=[], |
327 | | - expected_stdout_substring="No help for 'pdb'", |
| 325 | + expected_stdout_substring=expected_substring, |
328 | 326 | ) |
329 | 327 |
|
330 | 328 | def test_handling_pdb_prompts(self): |
|
0 commit comments