Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,16 @@ def test_number_validation_with_invalid_precision_invalid_scale():
assert False, "Did not raise Invalid for String"


def test_number_validation_with_non_finite_number():
schema = Schema({"number": Number(precision=6, scale=2)})
try:
schema({"number": 'Infinity'})
except MultipleInvalid as e:
assert str(e) == "Value has no precision for dictionary value @ data['number']"
else:
assert False, "Did not raise Invalid for Infinity"


def test_number_validation_with_valid_precision_scale_yield_decimal_true():
"""Test with Number with valid precision and scale"""
schema = Schema({"number": Number(precision=6, scale=2, yield_decimal=True)})
Expand Down
4 changes: 1 addition & 3 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,7 @@ def _get_precision_scale(self, number) -> typing.Tuple[int, int, Decimal]:
if isinstance(exp, int):
return (len(decimal_num.as_tuple().digits), -exp, decimal_num)
else:
# TODO: handle infinity and NaN
# raise Invalid(self.msg or 'Value has no precision')
raise TypeError("infinity and NaN have no precision")
raise Invalid(self.msg or 'Value has no precision')


class SomeOf(_WithSubValidators):
Expand Down