Ensure match pattern error isn't raised on empty errors (closes #3549)

This commit is contained in:
Ines Montani 2019-04-09 12:50:43 +02:00
parent 3ddb799f27
commit 4d198a7e92
2 changed files with 16 additions and 1 deletions

View File

@ -105,7 +105,7 @@ cdef class Matcher:
raise ValueError(Errors.E012.format(key=key)) raise ValueError(Errors.E012.format(key=key))
if self.validator: if self.validator:
errors[i] = validate_json(pattern, self.validator) errors[i] = validate_json(pattern, self.validator)
if errors: if any(err for err in errors.values()):
raise MatchPatternError(key, errors) raise MatchPatternError(key, errors)
key = self._normalize_key(key) key = self._normalize_key(key)
for pattern in patterns: for pattern in patterns:

View File

@ -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"}])