MCPcopy
hub / github.com/pydantic/pydantic / test_decimal_constraints_after_annotation

Function test_decimal_constraints_after_annotation

tests/test_annotated.py:623–637  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

621
622
623def test_decimal_constraints_after_annotation() -> None:
624 DecimalAnnotation = Annotated[Decimal, BeforeValidator(lambda v: v), Field(max_digits=10, decimal_places=4)]
625
626 ta = TypeAdapter(DecimalAnnotation)
627 assert ta.validate_python(Decimal('123.4567')) == Decimal('123.4567')
628
629 with pytest.raises(ValidationError) as e:
630 ta.validate_python(Decimal('123.45678'))
631
632 assert e.value.errors()[0]['type'] == 'decimal_max_places'
633
634 with pytest.raises(ValidationError) as e:
635 ta.validate_python(Decimal('12345678.901'))
636
637 assert e.value.errors()[0]['type'] == 'decimal_max_digits'

Callers

nothing calls this directly

Calls 5

validate_pythonMethod · 0.95
BeforeValidatorClass · 0.90
FieldFunction · 0.90
TypeAdapterClass · 0.90
errorsMethod · 0.45

Tested by

no test coverage detected