Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion samples/robot_copilot_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,26 @@ def json_should_be_valid(self) -> dict:
"""Assert that the last response is valid JSON and return the parsed dict."""
try:
data = json.loads(self._last_response)
return data
except json.JSONDecodeError as e:
raise AssertionError(
f"Invalid JSON: {e}\n\nRaw:\n{self._last_response[:300]}"
)

if not isinstance(data, dict):
raise AssertionError(
f"Expected JSON object (dict), but got {type(data).__name__}.\n"
f"Value: {str(data)[:300]}"
)
return data

def json_should_have_keys(self, *keys):
"""Assert that the parsed JSON contains all specified keys.

Example (Robot):
JSON Should Have Keys name age email
"""
data = self.json_should_be_valid()
# json_should_be_valid() already asserts isinstance(data, dict)
missing = set(keys) - set(data.keys())
if missing:
raise AssertionError(
Expand Down