MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_optional_nested_model

Function test_optional_nested_model

tests/test_models.py:52–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50
51
52def test_optional_nested_model() -> None:
53 class NestedModel(BaseModel):
54 nested: Optional[BasicModel]
55
56 m1 = NestedModel.construct(nested=None)
57 assert m1.nested is None
58
59 m2 = NestedModel.construct(nested={"foo": "bar"})
60 assert m2.nested is not None
61 assert m2.nested.foo == "bar"
62
63 # mismatched types
64 m3 = NestedModel.construct(nested={"foo"})
65 assert isinstance(cast(Any, m3.nested), set)
66 assert cast(Any, m3.nested) == {"foo"}
67
68
69def test_list_nested_model() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected