diff --git a/voluptuous/tests/tests.py b/voluptuous/tests/tests.py index c16cfa7..11e136b 100644 --- a/voluptuous/tests/tests.py +++ b/voluptuous/tests/tests.py @@ -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}) diff --git a/voluptuous/validators.py b/voluptuous/validators.py index 99bc523..7da697f 100644 --- a/voluptuous/validators.py +++ b/voluptuous/validators.py @@ -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))