MCPcopy
hub / github.com/openai/openai-python / test_optional_nested_model

Function test_optional_nested_model

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

Source from the content-addressed store, hash-verified

36
37
38def test_optional_nested_model() -> None:
39 class NestedModel(BaseModel):
40 nested: Optional[BasicModel]
41
42 m1 = NestedModel.construct(nested=None)
43 assert m1.nested is None
44
45 m2 = NestedModel.construct(nested={"foo": "bar"})
46 assert m2.nested is not None
47 assert m2.nested.foo == "bar"
48
49 # mismatched types
50 m3 = NestedModel.construct(nested={"foo"})
51 assert isinstance(cast(Any, m3.nested), set)
52 assert cast(Any, m3.nested) == {"foo"}
53
54
55def test_list_nested_model() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected