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

Function test_double_nested_union

tests/test_models.py:415–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

413
414
415def test_double_nested_union() -> None:
416 class SubModel1(BaseModel):
417 name: str
418
419 class SubModel2(BaseModel):
420 bar: str
421
422 class Model(BaseModel):
423 data: Dict[str, List[Union[SubModel1, SubModel2]]]
424
425 m = Model.construct(data={"foo": [{"bar": "baz"}, {"name": "Robert"}]})
426 assert len(m.data["foo"]) == 2
427
428 entry1 = m.data["foo"][0]
429 assert isinstance(entry1, SubModel2)
430 assert entry1.bar == "baz"
431
432 entry2 = m.data["foo"][1]
433 assert isinstance(entry2, SubModel1)
434 assert entry2.name == "Robert"
435
436 # TODO: test mismatched type
437
438
439def test_union_of_dict() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected