MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / assert_matches_model

Function assert_matches_model

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

Source from the content-addressed store, hash-verified

25
26
27def assert_matches_model(model: type[BaseModelT], value: BaseModelT, *, path: list[str]) -> bool:
28 for name, field in get_model_fields(model).items():
29 field_value = getattr(value, name)
30 if PYDANTIC_V2:
31 allow_none = False
32 else:
33 # in v1 nullability was structured differently
34 # https://docs.pydantic.dev/2.0/migration/#required-optional-and-nullable-fields
35 allow_none = getattr(field, "allow_none", False)
36
37 assert_matches_type(
38 field_outer_type(field),
39 field_value,
40 path=[*path, name],
41 allow_none=allow_none,
42 )
43
44 return True
45
46
47# 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