MCPcopy
hub / github.com/pydantic/pydantic / test_annotated_num

Function test_annotated_num

tests/test_validate_call.py:781–798  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

779
780
781def test_annotated_num():
782 @validate_call
783 def f(a: Annotated[int, Field(gt=0), Field(lt=10)]):
784 return a
785
786 assert f(5) == 5
787
788 with pytest.raises(ValidationError) as exc_info:
789 f(0)
790 assert exc_info.value.errors(include_url=False) == [
791 {'type': 'greater_than', 'loc': (0,), 'msg': 'Input should be greater than 0', 'input': 0, 'ctx': {'gt': 0}}
792 ]
793
794 with pytest.raises(ValidationError) as exc_info:
795 f(10)
796 assert exc_info.value.errors(include_url=False) == [
797 {'type': 'less_than', 'loc': (0,), 'msg': 'Input should be less than 10', 'input': 10, 'ctx': {'lt': 10}}
798 ]
799
800
801def test_annotated_discriminator():

Callers

nothing calls this directly

Calls 2

fFunction · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected