Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert Range tests so nan is excluded #195

Merged
merged 1 commit into from
Aug 17, 2016
Merged
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
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