test_forwards_compat_model_dump_json_method() — anthropic-sdk-python Function Reference
Architecture documentation for the test_forwards_compat_model_dump_json_method() function in test_models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 408c2b65_94a0_94ef_1053_fe9ba32398f6["test_forwards_compat_model_dump_json_method()"] 7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"] 408c2b65_94a0_94ef_1053_fe9ba32398f6 -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e style 408c2b65_94a0_94ef_1053_fe9ba32398f6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_models.py lines 603–630
def test_forwards_compat_model_dump_json_method() -> None:
class Model(BaseModel):
foo: Optional[str] = Field(alias="FOO", default=None)
m = Model(FOO="hello")
assert json.loads(m.model_dump_json()) == {"foo": "hello"}
assert json.loads(m.model_dump_json(include={"bar"})) == {}
assert json.loads(m.model_dump_json(include={"foo"})) == {"foo": "hello"}
assert json.loads(m.model_dump_json(by_alias=True)) == {"FOO": "hello"}
assert m.model_dump_json(indent=2) == '{\n "foo": "hello"\n}'
m2 = Model()
assert json.loads(m2.model_dump_json()) == {"foo": None}
assert json.loads(m2.model_dump_json(exclude_unset=True)) == {}
assert json.loads(m2.model_dump_json(exclude_none=True)) == {}
assert json.loads(m2.model_dump_json(exclude_defaults=True)) == {}
m3 = Model(FOO=None)
assert json.loads(m3.model_dump_json()) == {"foo": None}
assert json.loads(m3.model_dump_json(exclude_none=True)) == {}
if PYDANTIC_V1:
with pytest.raises(ValueError, match="round_trip is only supported in Pydantic v2"):
m.model_dump_json(round_trip=True)
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
m.model_dump_json(warnings=False)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_forwards_compat_model_dump_json_method() do?
test_forwards_compat_model_dump_json_method() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_forwards_compat_model_dump_json_method() defined?
test_forwards_compat_model_dump_json_method() is defined in tests/test_models.py at line 603.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free