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

Function test_dict_of_union

tests/test_models.py:395–412  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

393
394
395def test_dict_of_union() -> None:
396 class SubModel1(BaseModel):
397 name: str
398
399 class SubModel2(BaseModel):
400 foo: str
401
402 class Model(BaseModel):
403 data: Dict[str, Union[SubModel1, SubModel2]]
404
405 m = Model.construct(data={"hello": {"name": "there"}, "foo": {"foo": "bar"}})
406 assert len(list(m.data.keys())) == 2
407 assert isinstance(m.data["hello"], SubModel1)
408 assert m.data["hello"].name == "there"
409 assert isinstance(m.data["foo"], SubModel2)
410 assert m.data["foo"].foo == "bar"
411
412 # TODO: test mismatched type
413
414
415def test_double_nested_union() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected