Skip to content

Commit 20c5e17

Browse files
committed
adding tests
1 parent 7948574 commit 20c5e17

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/validators/test_decimal.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,31 @@ def test_non_finite_constrained_decimal_values(input_value, allow_inf_nan, expec
437437
def test_validate_scientific_notation_from_json(input_value, expected):
438438
v = SchemaValidator({'type': 'decimal'})
439439
assert v.validate_json(input_value) == expected
440+
441+
442+
def test_validate_max_digits_and_decimal_places() -> None:
443+
v = SchemaValidator({'type': 'decimal', 'max_digits': 5, 'decimal_places': 2})
444+
445+
# valid inputs
446+
assert v.validate_json('1.23') == Decimal('1.23')
447+
assert v.validate_json('123.45') == Decimal('123.45')
448+
assert v.validate_json('-123.45') == Decimal('-123.45')
449+
450+
# invalid inputs
451+
with pytest.raises(ValidationError):
452+
v.validate_json('1234.56') # too many digits
453+
with pytest.raises(ValidationError):
454+
v.validate_json('123.456') # too many decimal places
455+
with pytest.raises(ValidationError):
456+
v.validate_json('123456') # too many digits
457+
with pytest.raises(ValidationError):
458+
v.validate_json('abc') # not a valid decimal
459+
460+
461+
def test_validate_max_digits_and_decimal_places_edge_case() -> None:
462+
v = SchemaValidator({'type': 'decimal', 'max_digits': 34, 'decimal_places': 18})
463+
464+
# valid inputs
465+
assert v.validate_python(Decimal('9999999999999999.999999999999999999')) == Decimal(
466+
'9999999999999999.999999999999999999'
467+
)

0 commit comments

Comments
 (0)