Skip to content

Commit

Permalink
Merge pull request #195 from dangitall/exclude-nan-from-range
Browse files Browse the repository at this point in the history
Invert Range tests so nan is excluded
  • Loading branch information
alecthomas authored Aug 17, 2016
2 parents c684bae + e92c865 commit 81e05ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,8 @@ def fn(arg):

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'))
8 changes: 4 additions & 4 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,19 @@ def __init__(self, min=None, max=None, min_included=True,

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
Expand Down

0 comments on commit 81e05ef

Please sign in to comment.