test_to_dict() — anthropic-sdk-python Function Reference
Architecture documentation for the test_to_dict() function in test_models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 9b8688d3_eece_90b3_2564_12b367f4f0d2["test_to_dict()"] 7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"] 9b8688d3_eece_90b3_2564_12b367f4f0d2 -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e style 9b8688d3_eece_90b3_2564_12b367f4f0d2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_models.py lines 507–536
def test_to_dict() -> None:
class Model(BaseModel):
foo: Optional[str] = Field(alias="FOO", default=None)
m = Model(FOO="hello")
assert m.to_dict() == {"FOO": "hello"}
assert m.to_dict(use_api_names=False) == {"foo": "hello"}
m2 = Model()
assert m2.to_dict() == {}
assert m2.to_dict(exclude_unset=False) == {"FOO": None}
assert m2.to_dict(exclude_unset=False, exclude_none=True) == {}
assert m2.to_dict(exclude_unset=False, exclude_defaults=True) == {}
m3 = Model(FOO=None)
assert m3.to_dict() == {"FOO": None}
assert m3.to_dict(exclude_none=True) == {}
assert m3.to_dict(exclude_defaults=True) == {}
class Model2(BaseModel):
created_at: datetime
time_str = "2024-03-21T11:39:01.275859"
m4 = Model2.construct(created_at=time_str)
assert m4.to_dict(mode="python") == {"created_at": datetime.fromisoformat(time_str)}
assert m4.to_dict(mode="json") == {"created_at": time_str}
if PYDANTIC_V1:
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
m.to_dict(warnings=False)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_to_dict() do?
test_to_dict() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_to_dict() defined?
test_to_dict() is defined in tests/test_models.py at line 507.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free