Home / File/ test_legacy_response.py — anthropic-sdk-python Source File

test_legacy_response.py — anthropic-sdk-python Source File

Architecture documentation for test_legacy_response.py, a python file in the anthropic-sdk-python codebase. 10 imports, 0 dependents.

File python AnthropicClient AsyncAPI 10 imports 7 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  220a5d1f_6983_9c80_71b8_c5877a0fc71e["test_legacy_response.py"]
  28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5["json"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 37c05070_ca59_d596_7250_de9d1939227f
  9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 21de8837_7dae_989e_fdbb_1415c0770d90
  d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> d10c5377_2939_0f0b_cc44_8759393f2853
  4576f658_f93f_2a77_9ff8_4875c797aab6["anthropic._streaming"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 4576f658_f93f_2a77_9ff8_4875c797aab6
  9c2d34b7_fa28_dac8_c499_f65e981c87d8["anthropic._base_client"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> 9c2d34b7_fa28_dac8_c499_f65e981c87d8
  f9fce826_b216_5ab1_fca0_52dbed3ce2ad["anthropic._legacy_response"]
  220a5d1f_6983_9c80_71b8_c5877a0fc71e --> f9fce826_b216_5ab1_fca0_52dbed3ce2ad
  style 220a5d1f_6983_9c80_71b8_c5877a0fc71e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json
from typing import Any, Union, cast
from typing_extensions import Annotated

import httpx
import pytest
import pydantic

from anthropic import Anthropic, BaseModel
from anthropic._streaming import Stream
from anthropic._base_client import FinalRequestOptions
from anthropic._legacy_response import LegacyAPIResponse


class PydanticModel(pydantic.BaseModel): ...


def test_response_parse_mismatched_basemodel(client: Anthropic) -> None:
    response = LegacyAPIResponse(
        raw=httpx.Response(200, content=b"foo"),
        client=client,
        stream=False,
        stream_cls=None,
        cast_to=str,
        options=FinalRequestOptions.construct(method="get", url="/foo"),
    )

    with pytest.raises(
        TypeError,
        match="Pydantic models must subclass our base model type, e.g. `from anthropic import BaseModel`",
    ):
        response.parse(to=PydanticModel)


@pytest.mark.parametrize(
    "content, expected",
    [
        ("false", False),
        ("true", True),
        ("False", False),
        ("True", True),
        ("TrUe", True),
        ("FalSe", False),
    ],
)
def test_response_parse_bool(client: Anthropic, content: str, expected: bool) -> None:
    response = LegacyAPIResponse(
        raw=httpx.Response(200, content=content),
        client=client,
        stream=False,
        stream_cls=None,
        cast_to=str,
        options=FinalRequestOptions.construct(method="get", url="/foo"),
    )

    result = response.parse(to=bool)
    assert result is expected


def test_response_parse_custom_stream(client: Anthropic) -> None:
// ... (89 more lines)

Subdomains

Dependencies

  • anthropic
  • anthropic._base_client
  • anthropic._legacy_response
  • anthropic._streaming
  • httpx
  • json
  • pydantic
  • pytest
  • typing
  • typing_extensions

Frequently Asked Questions

What does test_legacy_response.py do?
test_legacy_response.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in test_legacy_response.py?
test_legacy_response.py defines 7 function(s): test_response_basemodel_request_id, test_response_parse_annotated_type, test_response_parse_bool, test_response_parse_custom_model, test_response_parse_custom_stream, test_response_parse_expect_model_union_non_json_content, test_response_parse_mismatched_basemodel.
What does test_legacy_response.py depend on?
test_legacy_response.py imports 10 module(s): anthropic, anthropic._base_client, anthropic._legacy_response, anthropic._streaming, httpx, json, pydantic, pytest, and 2 more.
Where is test_legacy_response.py in the architecture?
test_legacy_response.py is located at tests/test_legacy_response.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free