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

Function assert_matches_model

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

Source from the content-addressed store, hash-verified

39
40
41def assert_matches_model(model: type[BaseModelT], value: BaseModelT, *, path: list[str]) -> bool:
42 for name, field in get_model_fields(model).items():
43 field_value = getattr(value, name)
44 if PYDANTIC_V1:
45 # in v1 nullability was structured differently
46 # https://docs.pydantic.dev/2.0/migration/#required-optional-and-nullable-fields
47 allow_none = getattr(field, "allow_none", False)
48 else:
49 allow_none = False
50
51 assert_matches_type(
52 field_outer_type(field),
53 field_value,
54 path=[*path, name],
55 allow_none=allow_none,
56 )
57
58 return True
59
60
61# 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