|
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,37 +279,50 @@ def test_handling_other_message(self):
|
279 | 279 | expected_stdout="Some message.\n",
|
280 | 280 | )
|
281 | 281 |
|
282 |
| - def test_handling_help_for_command(self): |
283 |
| - """Test handling a request to display help for a command.""" |
| 282 | + @unittest.skipIf(sys.flags.optimize >= 2, "Help not available for -OO") |
| 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.""" |
284 | 296 | incoming = [
|
285 |
| - ("server", {"help": "ll"}), |
| 297 | + ("server", help_request), |
286 | 298 | ]
|
287 | 299 | self.do_test(
|
288 | 300 | incoming=incoming,
|
289 | 301 | expected_outgoing=[],
|
290 |
| - expected_stdout_substring="Usage: ll | longlist", |
| 302 | + expected_stdout_substring=expected_substring, |
291 | 303 | )
|
292 | 304 |
|
293 |
| - def test_handling_help_without_a_specific_topic(self): |
294 |
| - """Test handling a request to display a help overview.""" |
| 305 | + @unittest.skipIf(sys.flags.optimize < 2, "Needs -OO") |
| 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.""" |
295 | 319 | incoming = [
|
296 |
| - ("server", {"help": ""}), |
| 320 | + ("server", help_request), |
297 | 321 | ]
|
298 | 322 | self.do_test(
|
299 | 323 | incoming=incoming,
|
300 | 324 | expected_outgoing=[],
|
301 |
| - expected_stdout_substring="type help <topic>", |
302 |
| - ) |
303 |
| - |
304 |
| - def test_handling_help_pdb(self): |
305 |
| - """Test handling a request to display the full PDB manual.""" |
306 |
| - incoming = [ |
307 |
| - ("server", {"help": "pdb"}), |
308 |
| - ] |
309 |
| - self.do_test( |
310 |
| - incoming=incoming, |
311 |
| - expected_outgoing=[], |
312 |
| - expected_stdout_substring=">>> import pdb", |
| 325 | + expected_stdout_substring=expected_substring, |
313 | 326 | )
|
314 | 327 |
|
315 | 328 | def test_handling_pdb_prompts(self):
|
|
0 commit comments