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

Function test_double_nested_union

tests/test_models.py:381–402  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

379
380
381def test_double_nested_union() -> None:
382 class SubModel1(BaseModel):
383 name: str
384
385 class SubModel2(BaseModel):
386 bar: str
387
388 class Model(BaseModel):
389 data: Dict[str, List[Union[SubModel1, SubModel2]]]
390
391 m = Model.construct(data={"foo": [{"bar": "baz"}, {"name": "Robert"}]})
392 assert len(m.data["foo"]) == 2
393
394 entry1 = m.data["foo"][0]
395 assert isinstance(entry1, SubModel2)
396 assert entry1.bar == "baz"
397
398 entry2 = m.data["foo"][1]
399 assert isinstance(entry2, SubModel1)
400 assert entry2.name == "Robert"
401
402 # TODO: test mismatched type
403
404
405def test_union_of_dict() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected