|
1 | 1 | import io
|
2 |
| -import time |
3 | 2 | import itertools
|
4 | 3 | import json
|
5 | 4 | import os
|
|
8 | 7 | import socket
|
9 | 8 | import subprocess
|
10 | 9 | import sys
|
11 |
| -import tempfile |
12 | 10 | import textwrap
|
13 |
| -import threading |
14 | 11 | import unittest
|
15 | 12 | import unittest.mock
|
16 | 13 | from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
|
17 |
| -from pathlib import Path |
18 |
| -from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT |
19 |
| -from test.support.os_helper import temp_dir, TESTFN, unlink |
20 |
| -from typing import Dict, List, Optional, Tuple, Union, Any |
| 14 | +from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT, subTests |
| 15 | +from test.support.os_helper import TESTFN, unlink |
| 16 | +from typing import List |
21 | 17 |
|
22 | 18 | import pdb
|
23 | 19 | from pdb import _PdbServer, _PdbClient
|
@@ -283,37 +279,50 @@ def test_handling_other_message(self):
|
283 | 279 | expected_stdout="Some message.\n",
|
284 | 280 | )
|
285 | 281 |
|
286 |
| - def test_handling_help_for_command(self): |
287 |
| - """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.""" |
288 | 296 | incoming = [
|
289 |
| - ("server", {"help": "ll"}), |
| 297 | + ("server", help_request), |
290 | 298 | ]
|
291 | 299 | self.do_test(
|
292 | 300 | incoming=incoming,
|
293 | 301 | expected_outgoing=[],
|
294 |
| - expected_stdout_substring="Usage: ll | longlist", |
| 302 | + expected_stdout_substring=expected_substring, |
295 | 303 | )
|
296 | 304 |
|
297 |
| - def test_handling_help_without_a_specific_topic(self): |
298 |
| - """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.""" |
299 | 319 | incoming = [
|
300 |
| - ("server", {"help": ""}), |
| 320 | + ("server", help_request), |
301 | 321 | ]
|
302 | 322 | self.do_test(
|
303 | 323 | incoming=incoming,
|
304 | 324 | expected_outgoing=[],
|
305 |
| - expected_stdout_substring="type help <topic>", |
306 |
| - ) |
307 |
| - |
308 |
| - def test_handling_help_pdb(self): |
309 |
| - """Test handling a request to display the full PDB manual.""" |
310 |
| - incoming = [ |
311 |
| - ("server", {"help": "pdb"}), |
312 |
| - ] |
313 |
| - self.do_test( |
314 |
| - incoming=incoming, |
315 |
| - expected_outgoing=[], |
316 |
| - expected_stdout_substring=">>> import pdb", |
| 325 | + expected_stdout_substring=expected_substring, |
317 | 326 | )
|
318 | 327 |
|
319 | 328 | def test_handling_pdb_prompts(self):
|
@@ -1434,7 +1443,6 @@ def test_multi_line_commands(self):
|
1434 | 1443 |
|
1435 | 1444 |
|
1436 | 1445 | def _supports_remote_attaching():
|
1437 |
| - from contextlib import suppress |
1438 | 1446 | PROCESS_VM_READV_SUPPORTED = False
|
1439 | 1447 |
|
1440 | 1448 | try:
|
|
0 commit comments