Skip to content

Commit

Permalink
Merge pull request #197 from emarx/master
Browse files Browse the repository at this point in the history
Fix Exact Sequence to Match Lengths
  • Loading branch information
alecthomas authored Aug 23, 2016
2 parents 81e05ef + 406dca1 commit b052498
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
Schema, Required, Extra, Invalid, In, Remove, Literal,
Url, MultipleInvalid, LiteralInvalid, NotIn, Match, Email,
Replace, Range, Coerce, All, Any, Length, FqdnUrl, ALLOW_EXTRA, PREVENT_EXTRA,
validate_schema,
validate_schema, ExactSequence
)
from voluptuous.humanize import humanize_error


def test_exact_sequence():
schema = Schema(ExactSequence([int, int]))
try:
schema([1, 2, 3])
except Invalid:
assert True
else:
assert False, "Did not raise Invalid"
assert_equal(schema([1, 2]), [1, 2])


def test_required():
"""Verify that Required works."""
schema = Schema({Required('q'): 1})
Expand Down
2 changes: 1 addition & 1 deletion voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def __init__(self, validators, **kwargs):
self._schemas = [Schema(val, **kwargs) for val in validators]

def __call__(self, v):
if not isinstance(v, (list, tuple)):
if not isinstance(v, (list, tuple)) or len(v) != len(self._schemas):
raise ExactSequenceInvalid(self.msg)
try:
v = type(v)(schema(x) for x, schema in zip(v, self._schemas))
Expand Down

0 comments on commit b052498

Please sign in to comment.