MCPcopy
hub / github.com/pydantic/pydantic / test_merge_field_infos_ordering

Function test_merge_field_infos_ordering

tests/test_annotated.py:339–365  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

337
338
339def test_merge_field_infos_ordering() -> None:
340 TheType = Annotated[int, AfterValidator(lambda x: x), Field(le=2), AfterValidator(lambda x: x * 2), Field(lt=4)]
341
342 class Model(BaseModel):
343 x: TheType
344
345 assert Model(x=1).x == 2
346
347 with pytest.raises(ValidationError) as exc_info:
348 Model(x=2)
349 # insert_assert(exc_info.value.errors(include_url=False))
350 assert exc_info.value.errors(include_url=False) == [
351 {'type': 'less_than', 'loc': ('x',), 'msg': 'Input should be less than 4', 'input': 2, 'ctx': {'lt': 4}}
352 ]
353
354 with pytest.raises(ValidationError) as exc_info:
355 Model(x=3)
356 # insert_assert(exc_info.value.errors(include_url=False))
357 assert exc_info.value.errors(include_url=False) == [
358 {
359 'type': 'less_than_equal',
360 'loc': ('x',),
361 'msg': 'Input should be less than or equal to 2',
362 'input': 3,
363 'ctx': {'le': 2},
364 }
365 ]
366
367
368def test_validate_float_inf_nan_python() -> None:

Callers

nothing calls this directly

Calls 4

AfterValidatorClass · 0.90
FieldFunction · 0.90
ModelClass · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected