Skip to content

Commit f2fb9ff

Browse files
authored
test: improve coverage and organize test layout (#3085)
1 parent 60b7bee commit f2fb9ff

37 files changed

Lines changed: 546 additions & 11 deletions

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
[
2121
"test_example_workflows.py",
2222
"test_run_state.py",
23-
"test_sandbox_memory.py",
2423
"sandbox/capabilities/test_filesystem_capability.py",
2524
"sandbox/integration_tests/test_runner_pause_resume.py",
2625
"sandbox/test_client_options.py",
2726
"sandbox/test_exposed_ports.py",
2827
"sandbox/test_extract.py",
28+
"sandbox/test_memory.py",
2929
"sandbox/test_runtime.py",
3030
"sandbox/test_session_manager.py",
3131
"sandbox/test_session_sinks.py",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from agents.extensions.experimental.codex.items import AgentMessageItem, TodoItem, TodoListItem
6+
7+
8+
def test_dict_like_supports_mapping_access_for_dataclass_fields() -> None:
9+
item = AgentMessageItem(id="item-1", text="hello")
10+
11+
assert item["id"] == "item-1"
12+
assert item["text"] == "hello"
13+
assert item["type"] == "agent_message"
14+
assert item.get("text") == "hello"
15+
assert item.get("missing", "fallback") == "fallback"
16+
assert "id" in item
17+
assert "missing" not in item
18+
assert object() not in item
19+
assert list(item.keys()) == ["id", "text", "type"]
20+
21+
22+
def test_dict_like_raises_key_error_for_unknown_fields() -> None:
23+
item = AgentMessageItem(id="item-1", text="hello")
24+
25+
with pytest.raises(KeyError, match="missing"):
26+
_ = item["missing"]
27+
28+
29+
def test_dict_like_as_dict_recursively_converts_nested_dataclasses() -> None:
30+
item = TodoListItem(
31+
id="todo-list-1",
32+
items=[
33+
TodoItem(text="write tests", completed=True),
34+
TodoItem(text="run tests", completed=False),
35+
],
36+
)
37+
38+
assert item.as_dict() == {
39+
"id": "todo-list-1",
40+
"items": [
41+
{"text": "write tests", "completed": True},
42+
{"text": "run tests", "completed": False},
43+
],
44+
"type": "todo_list",
45+
}
File renamed without changes.

tests/extensions/test_runloop_capabilities_example.py renamed to tests/extensions/sandbox/test_runloop_capabilities_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
def _load_example_module() -> Any:
1313
path = (
14-
Path(__file__).resolve().parents[2]
14+
Path(__file__).resolve().parents[3]
1515
/ "examples"
1616
/ "sandbox"
1717
/ "extensions"
1818
/ "runloop"
1919
/ "capabilities.py"
2020
)
21-
module_name = "tests.extensions.runloop_capabilities_example"
21+
module_name = "tests.extensions.sandbox.runloop_capabilities_example"
2222
spec = importlib.util.spec_from_file_location(module_name, path)
2323
assert spec is not None
2424
assert spec.loader is not None
File renamed without changes.

0 commit comments

Comments
 (0)