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

Add sorted() for In and NotIn + fix tests #436

Merged
merged 1 commit into from
Nov 18, 2020
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
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