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

Function test_union_of_dict

tests/test_models.py:420–435  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

418
419
420def test_union_of_dict() -> None:
421 class SubModel1(BaseModel):
422 name: str
423
424 class SubModel2(BaseModel):
425 foo: str
426
427 class Model(BaseModel):
428 data: Union[Dict[str, SubModel1], Dict[str, SubModel2]]
429
430 m = Model.construct(data={"hello": {"name": "there"}, "foo": {"foo": "bar"}})
431 assert len(list(m.data.keys())) == 2
432 assert isinstance(m.data["hello"], SubModel1)
433 assert m.data["hello"].name == "there"
434 assert isinstance(m.data["foo"], SubModel1)
435 assert cast(Any, m.data["foo"]).foo == "bar"
436
437
438def test_iso8601_datetime() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected