Skip to content

Commit

Permalink
Clean up warnings in the test suite (explosion#11331)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianeboyd committed Dec 13, 2022
1 parent e3ef798 commit 1a5352e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions spacy/tests/doc/test_doc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy
import pytest
import warnings
from thinc.api import NumpyOps, get_current_ops

from spacy.attrs import DEP, ENT_IOB, ENT_TYPE, HEAD, IS_ALPHA, MORPH, POS
Expand Down Expand Up @@ -528,9 +529,9 @@ def test_doc_from_array_sent_starts(en_vocab):
# no warning using default attrs
attrs = doc._get_array_attrs()
arr = doc.to_array(attrs)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
new_doc.from_array(attrs, arr)
assert len(record) == 0
# only SENT_START uses SENT_START
attrs = [SENT_START]
arr = doc.to_array(attrs)
Expand Down
3 changes: 3 additions & 0 deletions spacy/tests/lang/ru/test_lemmatizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from spacy.tokens import Doc


pytestmark = pytest.mark.filterwarnings("ignore::DeprecationWarning")


def test_ru_doc_lemmatization(ru_lemmatizer):
words = ["мама", "мыла", "раму"]
pos = ["NOUN", "VERB", "NOUN"]
Expand Down
4 changes: 4 additions & 0 deletions spacy/tests/lang/uk/test_lemmatizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pytest
from spacy.tokens import Doc


pytestmark = pytest.mark.filterwarnings("ignore::DeprecationWarning")


def test_uk_lemmatizer(uk_lemmatizer):
"""Check that the default uk lemmatizer runs."""
doc = Doc(uk_lemmatizer.vocab, words=["a", "b", "c"])
Expand Down
9 changes: 5 additions & 4 deletions spacy/tests/matcher/test_phrase_matcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import warnings
import srsly
from mock import Mock

Expand Down Expand Up @@ -314,13 +315,13 @@ def test_phrase_matcher_validation(en_vocab):
matcher.add("TEST1", [doc1])
with pytest.warns(UserWarning):
matcher.add("TEST2", [doc2])
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
matcher.add("TEST3", [doc3])
assert not record.list
matcher = PhraseMatcher(en_vocab, attr="POS", validate=True)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
matcher.add("TEST4", [doc2])
assert not record.list


def test_attr_validation(en_vocab):
Expand Down
2 changes: 2 additions & 0 deletions spacy/training/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,5 @@ def ensure_shape(vectors_loc):
# store all the results in a list in memory
lines2 = open_file(vectors_loc)
yield from lines2
lines2.close()
lines.close()

0 comments on commit 1a5352e

Please sign in to comment.