Skip to content

Commit

Permalink
Fix a __ge__/__le__ bug. More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Koshkin committed Sep 29, 2018
1 parent 48b5ace commit 9379427
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
37 changes: 36 additions & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,52 @@
("hello", False),
]
),
# Greater
# Lesser
(
InstanceOf(int) < 100,
[
(10, True),
(10.1, False),
(100, False),
(200, False),
(-10, True),
(0, True),
]
),
# Lesser or Eq
(
InstanceOf(int) <= 100,
[
(10, True),
(10.1, False),
(100, True),
(200, False),
(-10, True),
(0, True),
]
),
# Greater
(
InstanceOf(int) > 100,
[
(10, False),
(100, False),
(200, True),
("helloworld", False),
(200.0, False),
]
),
# Greater or Eq
(
InstanceOf(int) >= 100,
[
(10, False),
(100, True),
(200, True),
("helloworld", False),
(200.0, False),
]
),
# Ints > 0 but not 100
(
(InstanceOf(int) > 0) & ~Just(100),
Expand Down
2 changes: 1 addition & 1 deletion watch/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BaseControlledValidator(WatchMe, PredicateController):

def generate_error_message(self, field_name, value):
return (
"It is not alowed to initilize %s object with a value of %s." %
"It is not allowed to initilize %s object with a value of %s." %
(
type(self).__qualname__, value
)
Expand Down
8 changes: 8 additions & 0 deletions watch/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import copy


# this should provide watch.builtins, which on its own
# depends on this core module
import watch


Expand Down Expand Up @@ -49,9 +51,15 @@ def __rshift__(self, value):
def __gt__(self, value):
return self & watch.builtins.GtThen(value)

def __ge__(self, value):
return self & watch.builtins.GtEqThen(value)

def __lt__(self, value):
return self & watch.builtins.LtThen(value)

def __le__(self, value):
return self & watch.builtins.LtEqThen(value)

def __invert__(self):
return watch.builtins.Not(self)

Expand Down

0 comments on commit 9379427

Please sign in to comment.