MCPcopy
hub / github.com/pydantic/pydantic / test_validation_alias_parse_data

Function test_validation_alias_parse_data

tests/test_aliases.py:622–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

620
621
622def test_validation_alias_parse_data():
623 class Model(BaseModel):
624 x: str = Field(validation_alias=AliasChoices('a', AliasPath('b', 1), 'c'))
625
626 assert Model.model_fields['x'].validation_alias == AliasChoices('a', AliasPath('b', 1), 'c')
627 assert Model.model_validate({'a': 'hello'}).x == 'hello'
628 assert Model.model_validate({'b': ['hello', 'world']}).x == 'world'
629 assert Model.model_validate({'c': 'test'}).x == 'test'
630 with pytest.raises(ValidationError) as exc_info:
631 Model.model_validate({'b': ['hello']})
632 assert exc_info.value.errors(include_url=False) == [
633 {
634 'type': 'missing',
635 'loc': ('a',),
636 'msg': 'Field required',
637 'input': {'b': ['hello']},
638 }
639 ]
640
641
642def test_validation_alias_priority():

Callers

nothing calls this directly

Calls 4

AliasChoicesClass · 0.90
AliasPathClass · 0.90
model_validateMethod · 0.80
errorsMethod · 0.45

Tested by

no test coverage detected