From e92c865d03c326717990537d0d9984773b3cb75b Mon Sep 17 00:00:00 2001 From: Dan Girellini Date: Wed, 17 Aug 2016 15:41:28 -0700 Subject: [PATCH] Invert Range tests so nan is excluded --- voluptuous/tests/tests.py | 5 +++++ 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 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')) 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 @@ 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