MCPcopy
hub / github.com/openai/openai-python / assert_matches_model

Function assert_matches_model

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

Source from the content-addressed store, hash-verified

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

Callers 1

assert_matches_typeFunction · 0.85

Calls 4

get_model_fieldsFunction · 0.90
field_outer_typeFunction · 0.90
assert_matches_typeFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected