Skip to content

Commit 577cfae

Browse files
authored
RangeValidator updates (#38)
* Add failing test * RangeValidator should handle invalid values * Version 0.0.16 release
1 parent efb9da6 commit 577cfae

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from setuptools import setup, find_packages
55
from setuptools.command.test import test as TestCommand
66

7-
__version__ = '0.0.15'
7+
__version__ = '0.0.16'
88

99

1010
class PyTest(TestCommand):

vladiate/test/test_validators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ def test_range_validator_fails():
167167
assert validator.bad == {'-42'}
168168

169169

170+
def test_range_validator_handles_bad_values():
171+
validator = RangeValidator(0, 100)
172+
with pytest.raises(ValidationException):
173+
validator.validate("foobar")
174+
175+
assert validator.bad == {'foobar'}
176+
177+
170178
def test_empty_validator_works():
171179
EmptyValidator().validate("")
172180

vladiate/validators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ def __init__(self, low, high):
144144
self.outside = set()
145145

146146
def validate(self, field, row={}):
147-
if not self.low <= float(field) <= self.high:
147+
try:
148+
value = float(field)
149+
if not self.low <= value <= self.high:
150+
raise ValueError
151+
except ValueError:
148152
self.outside.add(field)
149153
raise ValidationException(
150154
"'{}' is not in range {} to {}".format(

0 commit comments

Comments
 (0)