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

test_models.py — anthropic-sdk-python Source File

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

File python AnthropicClient AsyncAPI 9 imports 47 functions 21 classes

Entity Profile

Dependency Diagram

graph LR
  7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"]
  28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5["json"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  7e1d14c5_475e_409c_7c4e_1274f9d40aa9["datetime"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 7e1d14c5_475e_409c_7c4e_1274f9d40aa9
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 37c05070_ca59_d596_7250_de9d1939227f
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  7872e60b_4210_5600_119f_c5d08c52091e --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 21de8837_7dae_989e_fdbb_1415c0770d90
  d1009234_f799_7c53_7892_4262523206dd["anthropic._utils"]
  7872e60b_4210_5600_119f_c5d08c52091e --> d1009234_f799_7c53_7892_4262523206dd
  42bc4048_b76c_4d27_9cbe_884618df8c52["anthropic._compat"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 42bc4048_b76c_4d27_9cbe_884618df8c52
  7d132c4d_8665_7d6c_3d3d_3b1d1f22b9eb["anthropic._models"]
  7872e60b_4210_5600_119f_c5d08c52091e --> 7d132c4d_8665_7d6c_3d3d_3b1d1f22b9eb
  style 7872e60b_4210_5600_119f_c5d08c52091e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json
from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional, cast
from datetime import datetime, timezone
from typing_extensions import Literal, Annotated, TypeAliasType

import pytest
import pydantic
from pydantic import Field

from anthropic._utils import PropertyInfo
from anthropic._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
from anthropic._models import DISCRIMINATOR_CACHE, BaseModel, construct_type


class BasicModel(BaseModel):
    foo: str


@pytest.mark.parametrize("value", ["hello", 1], ids=["correct type", "mismatched"])
def test_basic(value: object) -> None:
    m = BasicModel.construct(foo=value)
    assert m.foo == value


def test_directly_nested_model() -> None:
    class NestedModel(BaseModel):
        nested: BasicModel

    m = NestedModel.construct(nested={"foo": "Foo!"})
    assert m.nested.foo == "Foo!"

    # mismatched types
    m = NestedModel.construct(nested="hello!")
    assert cast(Any, m.nested) == "hello!"


def test_optional_nested_model() -> None:
    class NestedModel(BaseModel):
        nested: Optional[BasicModel]

    m1 = NestedModel.construct(nested=None)
    assert m1.nested is None

    m2 = NestedModel.construct(nested={"foo": "bar"})
    assert m2.nested is not None
    assert m2.nested.foo == "bar"

    # mismatched types
    m3 = NestedModel.construct(nested={"foo"})
    assert isinstance(cast(Any, m3.nested), set)
    assert cast(Any, m3.nested) == {"foo"}


def test_list_nested_model() -> None:
    class NestedModel(BaseModel):
        nested: List[BasicModel]

    m = NestedModel.construct(nested=[{"foo": "bar"}, {"foo": "2"}])
    assert m.nested is not None
    assert isinstance(m.nested, list)
// ... (904 more lines)

Subdomains

Dependencies

  • anthropic._compat
  • anthropic._models
  • anthropic._utils
  • datetime
  • json
  • pydantic
  • pytest
  • typing
  • typing_extensions

Frequently Asked Questions

What does test_models.py do?
test_models.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_models.py?
test_models.py defines 47 function(s): test_aliases, test_annotated_types, test_basic, test_compat_method_no_error_for_warnings, test_deprecated_alias, test_dict_of_union, test_directly_nested_model, test_discriminated_union_case, test_discriminated_unions_invalid_data, test_discriminated_unions_invalid_data_nested_unions, and 37 more.
What does test_models.py depend on?
test_models.py imports 9 module(s): anthropic._compat, anthropic._models, anthropic._utils, datetime, json, pydantic, pytest, typing, and 1 more.
Where is test_models.py in the architecture?
test_models.py is located at tests/test_models.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