test_messages.py — anthropic-sdk-python Source File
Architecture documentation for test_messages.py, a python file in the anthropic-sdk-python codebase. 17 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8cc8cd20_a242_314f_b59d_2d554c624e7c["test_messages.py"] 31e115f3_5f92_0f4b_4468_e9937a5656c2["helpers.py"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 31e115f3_5f92_0f4b_4468_e9937a5656c2 d1b2725b_0ccb_90ce_868b_51db8c397a89["get_response"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> d1b2725b_0ccb_90ce_868b_51db8c397a89 cb02636d_b74b_7724_2966_191b6bc19c0f["to_async_iter"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> cb02636d_b74b_7724_2966_191b6bc19c0f bb0af148_44a9_df40_49c4_0fa6ceb5a403["os"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> bb0af148_44a9_df40_49c4_0fa6ceb5a403 506d0594_2a0d_4f14_1041_ed428dcfcac8["inspect"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 506d0594_2a0d_4f14_1041_ed428dcfcac8 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2 f6010db4_1656_22a8_b4ae_e0060d80d8c6["respx"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> f6010db4_1656_22a8_b4ae_e0060d80d8c6 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> d10c5377_2939_0f0b_cc44_8759393f2853 42bc4048_b76c_4d27_9cbe_884618df8c52["anthropic._compat"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 42bc4048_b76c_4d27_9cbe_884618df8c52 defbf27f_6bb9_ccfd_0689_e652d24b8263["anthropic.lib.streaming"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> defbf27f_6bb9_ccfd_0689_e652d24b8263 72fe4568_4346_84af_4911_f385907c87c3["anthropic.types.message"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> 72fe4568_4346_84af_4911_f385907c87c3 d00b1dce_284b_7f65_fa7d_8c0e6374c5f1["anthropic.resources.messages"] 8cc8cd20_a242_314f_b59d_2d554c624e7c --> d00b1dce_284b_7f65_fa7d_8c0e6374c5f1 style 8cc8cd20_a242_314f_b59d_2d554c624e7c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
import os
import inspect
from typing import Any, Set, TypeVar, cast
import httpx
import pytest
from respx import MockRouter
from anthropic import Stream, Anthropic, AsyncStream, AsyncAnthropic
from anthropic._compat import PYDANTIC_V1
from anthropic.lib.streaming import ParsedMessageStreamEvent
from anthropic.types.message import Message
from anthropic.resources.messages import DEPRECATED_MODELS
from anthropic.lib.streaming._messages import TRACKS_TOOL_INPUT
from .helpers import get_response, to_async_iter
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
api_key = "my-anthropic-api-key"
sync_client = Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
async_client = AsyncAnthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
_T = TypeVar("_T")
def assert_basic_response(events: list[ParsedMessageStreamEvent[None]], message: Message) -> None:
assert message.id == "msg_4QpJur2dWWDjF6C758FbBw5vm12BaVipnK"
assert message.model == "claude-3-opus-latest"
assert message.role == "assistant"
assert message.stop_reason == "end_turn"
assert message.stop_sequence is None
assert message.type == "message"
assert len(message.content) == 1
content = message.content[0]
assert content.type == "text"
assert content.text == "Hello there!"
assert [e.type for e in events] == [
"message_start",
"content_block_start",
"content_block_delta",
"text",
"content_block_delta",
"text",
"content_block_delta",
"text",
"content_block_stop",
"message_delta",
]
def assert_tool_use_response(events: list[ParsedMessageStreamEvent[None]], message: Message) -> None:
assert message.id == "msg_019Q1hrJbZG26Fb9BQhrkHEr"
assert message.model == "claude-sonnet-4-20250514"
assert message.role == "assistant"
assert message.stop_reason == "tool_use"
// ... (279 more lines)
Domain
Subdomains
Functions
Dependencies
- anthropic
- anthropic._compat
- anthropic.lib.streaming
- anthropic.lib.streaming._messages
- anthropic.resources.messages
- anthropic.types.content_block
- anthropic.types.message
- get_response
- helpers.py
- httpx
- inspect
- os
- pydantic
- pytest
- respx
- to_async_iter
- 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, SyncAPI subdomain.
What functions are defined in test_messages.py?
test_messages.py defines 4 function(s): assert_basic_response, assert_tool_use_response, test_stream_method_definition_in_sync, test_tracks_tool_input_type_alias_is_up_to_date.
What does test_messages.py depend on?
test_messages.py imports 17 module(s): anthropic, anthropic._compat, anthropic.lib.streaming, anthropic.lib.streaming._messages, anthropic.resources.messages, anthropic.types.content_block, anthropic.types.message, get_response, and 9 more.
Where is test_messages.py in the architecture?
test_messages.py is located at tests/lib/streaming/test_messages.py (domain: AnthropicClient, subdomain: SyncAPI, directory: tests/lib/streaming).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free