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

Function test_dict_of_union

tests/test_models.py:376–393  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

374
375
376def test_dict_of_union() -> None:
377 class SubModel1(BaseModel):
378 name: str
379
380 class SubModel2(BaseModel):
381 foo: str
382
383 class Model(BaseModel):
384 data: Dict[str, Union[SubModel1, SubModel2]]
385
386 m = Model.construct(data={"hello": {"name": "there"}, "foo": {"foo": "bar"}})
387 assert len(list(m.data.keys())) == 2
388 assert isinstance(m.data["hello"], SubModel1)
389 assert m.data["hello"].name == "there"
390 assert isinstance(m.data["foo"], SubModel2)
391 assert m.data["foo"].foo == "bar"
392
393 # TODO: test mismatched type
394
395
396def test_double_nested_union() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected