MCPcopy Index your code
hub / github.com/openai/openai-python / test_list_nested_model

Function test_list_nested_model

tests/test_models.py:55–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53
54
55def test_list_nested_model() -> None:
56 class NestedModel(BaseModel):
57 nested: List[BasicModel]
58
59 m = NestedModel.construct(nested=[{"foo": "bar"}, {"foo": "2"}])
60 assert m.nested is not None
61 assert isinstance(m.nested, list)
62 assert len(m.nested) == 2
63 assert m.nested[0].foo == "bar"
64 assert m.nested[1].foo == "2"
65
66 # mismatched types
67 m = NestedModel.construct(nested=True)
68 assert cast(Any, m.nested) is True
69
70 m = NestedModel.construct(nested=[False])
71 assert cast(Any, m.nested) == [False]
72
73
74def test_optional_list_nested_model() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected