Skip to content

Commit 0e90926

Browse files
authored
[3.14] gh-136438: Make sure test_remote_pdb pass with all optimization levels (GH-136788) (GH-136855)
(cherry picked from commit 588d9fb)
1 parent 2cb3b53 commit 0e90926

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

Lib/test/test_remote_pdb.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import time
32
import itertools
43
import json
54
import os
@@ -8,16 +7,13 @@
87
import socket
98
import subprocess
109
import sys
11-
import tempfile
1210
import textwrap
13-
import threading
1411
import unittest
1512
import unittest.mock
1613
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
2117

2218
import pdb
2319
from pdb import _PdbServer, _PdbClient
@@ -283,37 +279,50 @@ def test_handling_other_message(self):
283279
expected_stdout="Some message.\n",
284280
)
285281

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."""
288296
incoming = [
289-
("server", {"help": "ll"}),
297+
("server", help_request),
290298
]
291299
self.do_test(
292300
incoming=incoming,
293301
expected_outgoing=[],
294-
expected_stdout_substring="Usage: ll | longlist",
302+
expected_stdout_substring=expected_substring,
295303
)
296304

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."""
299319
incoming = [
300-
("server", {"help": ""}),
320+
("server", help_request),
301321
]
302322
self.do_test(
303323
incoming=incoming,
304324
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,
317326
)
318327

319328
def test_handling_pdb_prompts(self):
@@ -1434,7 +1443,6 @@ def test_multi_line_commands(self):
14341443

14351444

14361445
def _supports_remote_attaching():
1437-
from contextlib import suppress
14381446
PROCESS_VM_READV_SUPPORTED = False
14391447

14401448
try:

0 commit comments

Comments
 (0)