From 4d198a7e92f813fb9df2ade72fbeaf847284a7a0 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Tue, 9 Apr 2019 12:50:43 +0200 Subject: [PATCH] Ensure match pattern error isn't raised on empty errors (closes #3549) --- spacy/matcher/matcher.pyx | 2 +- spacy/tests/regression/test_issue3549.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 spacy/tests/regression/test_issue3549.py diff --git a/spacy/matcher/matcher.pyx b/spacy/matcher/matcher.pyx index 37218ce0d..b58c0e072 100644 --- a/spacy/matcher/matcher.pyx +++ b/spacy/matcher/matcher.pyx @@ -105,7 +105,7 @@ cdef class Matcher: raise ValueError(Errors.E012.format(key=key)) if self.validator: errors[i] = validate_json(pattern, self.validator) - if errors: + if any(err for err in errors.values()): raise MatchPatternError(key, errors) key = self._normalize_key(key) for pattern in patterns: diff --git a/spacy/tests/regression/test_issue3549.py b/spacy/tests/regression/test_issue3549.py new file mode 100644 index 000000000..3932bf19c --- /dev/null +++ b/spacy/tests/regression/test_issue3549.py @@ -0,0 +1,15 @@ +# coding: utf8 +from __future__ import unicode_literals + +import pytest +from spacy.matcher import Matcher +from spacy.errors import MatchPatternError + + +def test_issue3549(en_vocab): + """Test that match pattern validation doesn't raise on empty errors.""" + matcher = Matcher(en_vocab, validate=True) + pattern = [{"LOWER": "hello"}, {"LOWER": "world"}] + matcher.add("GOOD", None, pattern) + with pytest.raises(MatchPatternError): + matcher.add("BAD", None, [{"X": "Y"}])