-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtest_types.py
More file actions
151 lines (129 loc) · 5.57 KB
/
test_types.py
File metadata and controls
151 lines (129 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""Tests for Claude SDK type definitions."""
from claude_agent_sdk import (
AssistantMessage,
ClaudeAgentOptions,
ResultMessage,
)
from claude_agent_sdk.types import (
TextBlock,
ThinkingBlock,
ToolResultBlock,
ToolUseBlock,
UserMessage,
)
class TestMessageTypes:
"""Test message type creation and validation."""
def test_user_message_creation(self):
"""Test creating a UserMessage."""
msg = UserMessage(content="Hello, Claude!")
assert msg.content == "Hello, Claude!"
def test_assistant_message_with_text(self):
"""Test creating an AssistantMessage with text content."""
text_block = TextBlock(text="Hello, human!")
msg = AssistantMessage(content=[text_block], model="claude-opus-4-1-20250805")
assert len(msg.content) == 1
assert msg.content[0].text == "Hello, human!"
def test_assistant_message_with_thinking(self):
"""Test creating an AssistantMessage with thinking content."""
thinking_block = ThinkingBlock(thinking="I'm thinking...", signature="sig-123")
msg = AssistantMessage(
content=[thinking_block], model="claude-opus-4-1-20250805"
)
assert len(msg.content) == 1
assert msg.content[0].thinking == "I'm thinking..."
assert msg.content[0].signature == "sig-123"
def test_tool_use_block(self):
"""Test creating a ToolUseBlock."""
block = ToolUseBlock(
id="tool-123", name="Read", input={"file_path": "/test.txt"}
)
assert block.id == "tool-123"
assert block.name == "Read"
assert block.input["file_path"] == "/test.txt"
def test_tool_result_block(self):
"""Test creating a ToolResultBlock."""
block = ToolResultBlock(
tool_use_id="tool-123", content="File contents here", is_error=False
)
assert block.tool_use_id == "tool-123"
assert block.content == "File contents here"
assert block.is_error is False
def test_result_message(self):
"""Test creating a ResultMessage."""
msg = ResultMessage(
subtype="success",
duration_ms=1500,
duration_api_ms=1200,
is_error=False,
num_turns=1,
session_id="session-123",
total_cost_usd=0.01,
)
assert msg.subtype == "success"
assert msg.total_cost_usd == 0.01
assert msg.session_id == "session-123"
class TestOptions:
"""Test Options configuration."""
def test_default_options(self):
"""Test Options with default values."""
options = ClaudeAgentOptions()
assert options.allowed_tools == []
assert options.system_prompt is None
assert options.permission_mode is None
assert options.continue_conversation is False
assert options.disallowed_tools == []
def test_claude_code_options_with_tools(self):
"""Test Options with built-in tools."""
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write", "Edit"], disallowed_tools=["Bash"]
)
assert options.allowed_tools == ["Read", "Write", "Edit"]
assert options.disallowed_tools == ["Bash"]
def test_claude_code_options_with_permission_mode(self):
"""Test Options with permission mode."""
options = ClaudeAgentOptions(permission_mode="bypassPermissions")
assert options.permission_mode == "bypassPermissions"
options_plan = ClaudeAgentOptions(permission_mode="plan")
assert options_plan.permission_mode == "plan"
options_default = ClaudeAgentOptions(permission_mode="default")
assert options_default.permission_mode == "default"
options_accept = ClaudeAgentOptions(permission_mode="acceptEdits")
assert options_accept.permission_mode == "acceptEdits"
def test_claude_code_options_with_system_prompt_string(self):
"""Test Options with system prompt as string."""
options = ClaudeAgentOptions(
system_prompt="You are a helpful assistant.",
)
assert options.system_prompt == "You are a helpful assistant."
def test_claude_code_options_with_system_prompt_preset(self):
"""Test Options with system prompt preset."""
options = ClaudeAgentOptions(
system_prompt={"type": "preset", "preset": "claude_code"},
)
assert options.system_prompt == {"type": "preset", "preset": "claude_code"}
def test_claude_code_options_with_system_prompt_preset_and_append(self):
"""Test Options with system prompt preset and append."""
options = ClaudeAgentOptions(
system_prompt={
"type": "preset",
"preset": "claude_code",
"append": "Be concise.",
},
)
assert options.system_prompt == {
"type": "preset",
"preset": "claude_code",
"append": "Be concise.",
}
def test_claude_code_options_with_session_continuation(self):
"""Test Options with session continuation."""
options = ClaudeAgentOptions(continue_conversation=True, resume="session-123")
assert options.continue_conversation is True
assert options.resume == "session-123"
def test_claude_code_options_with_model_specification(self):
"""Test Options with model specification."""
options = ClaudeAgentOptions(
model="claude-sonnet-4-5", permission_prompt_tool_name="CustomTool"
)
assert options.model == "claude-sonnet-4-5"
assert options.permission_prompt_tool_name == "CustomTool"