Skip to content

Commit a40ba03

Browse files
committed
Creating a dedicated assert for capabilities and adjusting 'get_capability' to raise.
1 parent 0824e3c commit a40ba03

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def as_dict(self):
135135
return source_dict
136136

137137

138-
class NotSupportedError(Exception):
138+
class NotSupportedError(KeyError):
139139
"""Raised if a feature is not supported due to its capabilities."""
140140

141141

@@ -495,11 +495,13 @@ def wait_for_terminated(self, timeout: Optional[float] = None):
495495
raise ValueError("didn't get terminated event")
496496
return event_dict
497497

498-
def get_capability(self, key, default=None):
498+
def get_capability(self, key):
499499
"""Get a value for the given key if it there is a key/value pair in
500500
the capabilities reported by the adapter.
501501
"""
502-
return self.capabilities.get(key, default)
502+
if key in self.capabilities:
503+
return self.capabilities[key]
504+
raise NotSupportedError(key)
503505

504506
def get_threads(self):
505507
if self.threads is None:
@@ -767,8 +769,7 @@ def request_continue(self, threadId=None, singleThread=False):
767769
def request_restart(self, restartArguments=None):
768770
if self.exit_status is not None:
769771
raise ValueError("request_restart called after process exited")
770-
if not self.get_capability("supportsRestartRequest", False):
771-
raise NotSupportedError("supportsRestartRequest is not set")
772+
self.get_capability("supportsRestartRequest")
772773
command_dict = {
773774
"command": "restart",
774775
"type": "request",
@@ -981,8 +982,7 @@ def request_stepIn(self, threadId, targetId, granularity="statement"):
981982
def request_stepInTargets(self, frameId):
982983
if self.exit_status is not None:
983984
raise ValueError("request_stepInTargets called after process exited")
984-
if not self.get_capability("supportsStepInTargetsRequest", False):
985-
raise NotSupportedError("supportsStepInTargetsRequest is not set")
985+
self.get_capability("supportsStepInTargetsRequest")
986986
args_dict = {"frameId": frameId}
987987
command_dict = {
988988
"command": "stepInTargets",

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ def waitUntil(self, condition_callback):
128128
time.sleep(0.5)
129129
return False
130130

131+
def assertCapabilityIsSet(self, key: str, msg: Optional[str] = None) -> None:
132+
"""Assert that given capability is set in the client."""
133+
self.assertIn(key, self.dap_server.capabilities, msg)
134+
self.assertTrue(self.dap_server.capabilities[key], msg)
135+
136+
def assertCapabilityIsNotSet(self, key: str, msg: Optional[str] = None) -> None:
137+
"""Assert that given capability is not set in the client."""
138+
if key in self.dap_server.capabilities:
139+
self.assertFalse(self.dap_server.capabilities[key], msg)
140+
131141
def verify_breakpoint_hit(self, breakpoint_ids, timeout=DEFAULT_TIMEOUT):
132142
"""Wait for the process we are debugging to stop, and verify we hit
133143
any breakpoint location in the "breakpoint_ids" array.

0 commit comments

Comments
 (0)