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

Function test_double_nested_union

tests/test_models.py:396–417  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

394
395
396def test_double_nested_union() -> None:
397 class SubModel1(BaseModel):
398 name: str
399
400 class SubModel2(BaseModel):
401 bar: str
402
403 class Model(BaseModel):
404 data: Dict[str, List[Union[SubModel1, SubModel2]]]
405
406 m = Model.construct(data={"foo": [{"bar": "baz"}, {"name": "Robert"}]})
407 assert len(m.data["foo"]) == 2
408
409 entry1 = m.data["foo"][0]
410 assert isinstance(entry1, SubModel2)
411 assert entry1.bar == "baz"
412
413 entry2 = m.data["foo"][1]
414 assert isinstance(entry2, SubModel1)
415 assert entry2.name == "Robert"
416
417 # TODO: test mismatched type
418
419
420def test_union_of_dict() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected