Skip to content

Commit

Permalink
Add sorted() for In and NotIn + fix tests (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacegaier authored Nov 18, 2020
1 parent ffa09b4 commit 997c8db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ def test_iterate_candidates():

def test_in():
"""Verify that In works."""
schema = Schema({"color": In(frozenset(["blue", "red", "yellow"]))})
schema = Schema({"color": In(frozenset(["red", "blue", "yellow"]))})
schema({"color": "blue"})
try:
schema({"color": "orange"})
except Invalid as e:
assert_equal(str(e), "value is not allowed for dictionary value @ data['color']")
assert_equal(str(e), "value must be one of ['blue', 'red', 'yellow'] for dictionary value @ data['color']")
else:
assert False, "Did not raise InInvalid"


def test_not_in():
"""Verify that NotIn works."""
schema = Schema({"color": NotIn(frozenset(["blue", "red", "yellow"]))})
schema = Schema({"color": NotIn(frozenset(["red", "blue", "yellow"]))})
schema({"color": "orange"})
try:
schema({"color": "blue"})
except Invalid as e:
assert_equal(str(e), "value is not allowed for dictionary value @ data['color']")
assert_equal(str(e), "value must not be one of ['blue', 'red', 'yellow'] for dictionary value @ data['color']")
else:
assert False, "Did not raise NotInInvalid"

Expand Down
4 changes: 2 additions & 2 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def __call__(self, v):
check = True
if check:
raise InInvalid(self.msg or
'value must be one of {}'.format(self.container))
'value must be one of {}'.format(sorted(self.container)))
return v

def __repr__(self):
Expand All @@ -759,7 +759,7 @@ def __call__(self, v):
check = True
if check:
raise NotInInvalid(self.msg or
'value must not be one of {}'.format(self.container))
'value must not be one of {}'.format(sorted(self.container)))
return v

def __repr__(self):
Expand Down

0 comments on commit 997c8db

Please sign in to comment.