diff options
author | Alec Thomas <alec@swapoff.org> | 2016-08-18 09:11:33 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-18 09:11:33 +1000 |
commit | 81e05ef2c363702a5946006ea3b172c296aee68d (patch) | |
tree | 8a42eb9e3d01ef630beeec24fdea80a97d45422b | |
parent | c684bae5d50ac685133d30e52cfa6a60877a7bae (diff) | |
parent | e92c865d03c326717990537d0d9984773b3cb75b (diff) | |
download | voluptuous-81e05ef2c363702a5946006ea3b172c296aee68d.tar.gz |
Merge pull request #195 from dangitall/exclude-nan-from-range
Invert Range tests so nan is excluded
-rw-r--r-- | voluptuous/tests/tests.py | 5 | ||||
-rw-r--r-- | voluptuous/validators.py | 8 |
2 files changed, 9 insertions, 4 deletions
diff --git a/voluptuous/tests/tests.py b/voluptuous/tests/tests.py index 2b77272..c16cfa7 100644 --- a/voluptuous/tests/tests.py +++ b/voluptuous/tests/tests.py @@ -419,3 +419,8 @@ def test_schema_decorator(): fn(1) assert_raises(Invalid, fn, 1.0) + + +def test_range_exlcudes_nan(): + s = Schema(Range(min=0, max=10)) + assert_raises(MultipleInvalid, s, float('nan')) diff --git a/voluptuous/validators.py b/voluptuous/validators.py index c264599..99bc523 100644 --- a/voluptuous/validators.py +++ b/voluptuous/validators.py @@ -475,19 +475,19 @@ class Range(object): def __call__(self, v): if self.min_included: - if self.min is not None and v < self.min: + if self.min is not None and not v >= self.min: raise RangeInvalid( self.msg or 'value must be at least %s' % self.min) else: - if self.min is not None and v <= self.min: + if self.min is not None and not v > self.min: raise RangeInvalid( self.msg or 'value must be higher than %s' % self.min) if self.max_included: - if self.max is not None and v > self.max: + if self.max is not None and not v <= self.max: raise RangeInvalid( self.msg or 'value must be at most %s' % self.max) else: - if self.max is not None and v >= self.max: + if self.max is not None and not v < self.max: raise RangeInvalid( self.msg or 'value must be lower than %s' % self.max) return v |