MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / assert_matches_model

Function assert_matches_model

tests/utils.py:28–45  ·  view source on GitHub ↗
(model: type[BaseModelT], value: BaseModelT, *, path: list[str])

Source from the content-addressed store, hash-verified

26
27
28def assert_matches_model(model: type[BaseModelT], value: BaseModelT, *, path: list[str]) -> bool:
29 for name, field in get_model_fields(model).items():
30 field_value = getattr(value, name)
31 if PYDANTIC_V1:
32 # in v1 nullability was structured differently
33 # https://docs.pydantic.dev/2.0/migration/#required-optional-and-nullable-fields
34 allow_none = getattr(field, "allow_none", False)
35 else:
36 allow_none = False
37
38 assert_matches_type(
39 field_outer_type(field),
40 field_value,
41 path=[*path, name],
42 allow_none=allow_none,
43 )
44
45 return True
46
47
48# Note: the `path` argument is only used to improve error messages when `--showlocals` is used

Callers 1

assert_matches_typeFunction · 0.85

Calls 3

get_model_fieldsFunction · 0.90
field_outer_typeFunction · 0.90
assert_matches_typeFunction · 0.85

Tested by

no test coverage detected