test_messages.py — anthropic-sdk-python Source File
Architecture documentation for test_messages.py, a python file in the anthropic-sdk-python codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 2e600497_5282_f76f_a53c_ea19bd3e90f3["test_messages.py"] 077dc885_0b93_48bf_b408_eb69a4ebc905["snapshots"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 077dc885_0b93_48bf_b408_eb69a4ebc905 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2 f6010db4_1656_22a8_b4ae_e0060d80d8c6["respx"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> f6010db4_1656_22a8_b4ae_e0060d80d8c6 21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 21de8837_7dae_989e_fdbb_1415c0770d90 8cc1f0ad_0f79_35fa_324c_9980bd002940["inline_snapshot"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 8cc1f0ad_0f79_35fa_324c_9980bd002940 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> d10c5377_2939_0f0b_cc44_8759393f2853 72fe4568_4346_84af_4911_f385907c87c3["anthropic.types.message"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 72fe4568_4346_84af_4911_f385907c87c3 285f3833_8260_a440_881b_f2d5c5cc8742["anthropic.types.parsed_message"] 2e600497_5282_f76f_a53c_ea19bd3e90f3 --> 285f3833_8260_a440_881b_f2d5c5cc8742 style 2e600497_5282_f76f_a53c_ea19bd3e90f3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import List
import pytest
from respx import MockRouter
from pydantic import BaseModel
from inline_snapshot import external, snapshot
from anthropic import Anthropic, AsyncAnthropic, _compat
from anthropic.types.message import Message
from anthropic.types.parsed_message import ParsedMessage
from ..snapshots import make_snapshot_request, make_async_snapshot_request, make_async_stream_snapshot_request
class OrderItem(BaseModel):
product_name: str
price: float
quantity: int
class OrderDetails(BaseModel):
items: List[OrderItem]
total: float
@pytest.mark.skipif(_compat.PYDANTIC_V1, reason="structured outputs not supported with pydantic v1")
class TestSyncParse:
@pytest.mark.respx(base_url="http://127.0.0.1:4010")
def test_parse_with_pydantic_model(self, client: Anthropic, respx_mock: MockRouter) -> None:
"""Test sync messages.parse() with a Pydantic model output_format."""
def parse_message(c: Anthropic) -> ParsedMessage[OrderItem]:
return c.messages.parse(
model="claude-sonnet-4-5",
messages=[
{
"role": "user",
"content": "Extract: I want to order 2 Green Tea at $5.50 each",
}
],
output_format=OrderItem,
max_tokens=1024,
)
response = make_snapshot_request(
parse_message,
content_snapshot=snapshot(
'{"model":"claude-sonnet-4-5","id":"msg_01ParseTest001","type":"message","role":"assistant","content":[{"type":"text","text":"{\\"product_name\\":\\"Green Tea\\",\\"price\\":5.5,\\"quantity\\":2}"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":50,"output_tokens":20}}'
),
respx_mock=respx_mock,
mock_client=client,
path="/v1/messages",
)
assert response.parsed_output is not None
assert isinstance(response.parsed_output, OrderItem)
assert response.parsed_output.product_name == "Green Tea"
assert response.parsed_output.price == 5.5
assert response.parsed_output.quantity == 2
// ... (140 more lines)
Domain
Subdomains
Dependencies
- anthropic
- anthropic.types.message
- anthropic.types.parsed_message
- inline_snapshot
- pydantic
- pytest
- respx
- snapshots
- typing
Source
Frequently Asked Questions
What does test_messages.py do?
test_messages.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What does test_messages.py depend on?
test_messages.py imports 9 module(s): anthropic, anthropic.types.message, anthropic.types.parsed_message, inline_snapshot, pydantic, pytest, respx, snapshots, and 1 more.
Where is test_messages.py in the architecture?
test_messages.py is located at tests/lib/_parse/test_messages.py (domain: AnthropicClient, subdomain: Authentication, directory: tests/lib/_parse).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free