MCPcopy
hub / github.com/pydantic/pydantic / test_simple

Function test_simple

tests/test_validators.py:192–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190
191
192def test_simple():
193 class Model(BaseModel):
194 a: str
195
196 @field_validator('a')
197 @classmethod
198 def check_a(cls, v: Any):
199 if 'foobar' not in v:
200 raise ValueError('"foobar" not found in a')
201 return v
202
203 assert Model(a='this is foobar good').a == 'this is foobar good'
204
205 with pytest.raises(ValidationError) as exc_info:
206 Model(a='snap')
207 assert exc_info.value.errors(include_url=False) == [
208 {
209 'ctx': {'error': HasRepr(repr(ValueError('"foobar" not found in a')))},
210 'input': 'snap',
211 'loc': ('a',),
212 'msg': 'Value error, "foobar" not found in a',
213 'type': 'value_error',
214 }
215 ]
216
217
218def test_int_validation():

Callers

nothing calls this directly

Calls 2

ModelClass · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected