()
| 620 | |
| 621 | |
| 622 | def 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 | |
| 642 | def test_validation_alias_priority(): |
nothing calls this directly
no test coverage detected