MCPcopy
hub / github.com/pydantic/pydantic / test_annotated_validator_after

Function test_annotated_validator_after

tests/test_validators.py:51–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50
51def test_annotated_validator_after() -> None:
52 MyInt = Annotated[int, AfterValidator(lambda x, _info: x if x != -1 else 0)]
53
54 class Model(BaseModel):
55 x: MyInt
56
57 assert Model(x=0).x == 0
58 assert Model(x=-1).x == 0
59 assert Model(x=-2).x == -2
60 assert Model(x=1).x == 1
61 assert Model(x='-1').x == 0
62
63
64def test_annotated_validator_before() -> None:

Callers

nothing calls this directly

Calls 2

AfterValidatorClass · 0.90
ModelClass · 0.70

Tested by

no test coverage detected