mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
use clean_underscore fixture
This commit is contained in:
parent
6e717c62ed
commit
b49a3afd0c
|
@ -7,6 +7,15 @@ from spacy.tokens import Doc, Span, Token
|
||||||
from spacy.tokens.underscore import Underscore
|
from spacy.tokens.underscore import Underscore
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function", autouse=True)
|
||||||
|
def clean_underscore():
|
||||||
|
# reset the Underscore object after the test, to avoid having state copied across tests
|
||||||
|
yield
|
||||||
|
Underscore.doc_extensions = {}
|
||||||
|
Underscore.span_extensions = {}
|
||||||
|
Underscore.token_extensions = {}
|
||||||
|
|
||||||
|
|
||||||
def test_create_doc_underscore():
|
def test_create_doc_underscore():
|
||||||
doc = Mock()
|
doc = Mock()
|
||||||
doc.doc = doc
|
doc.doc = doc
|
||||||
|
|
|
@ -6,6 +6,7 @@ import re
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from spacy.matcher import Matcher, DependencyMatcher
|
from spacy.matcher import Matcher, DependencyMatcher
|
||||||
from spacy.tokens import Doc, Token
|
from spacy.tokens import Doc, Token
|
||||||
|
from ..doc.test_underscore import clean_underscore
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -200,6 +201,7 @@ def test_matcher_any_token_operator(en_vocab):
|
||||||
assert matches[2] == "test hello world"
|
assert matches[2] == "test hello world"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("clean_underscore")
|
||||||
def test_matcher_extension_attribute(en_vocab):
|
def test_matcher_extension_attribute(en_vocab):
|
||||||
matcher = Matcher(en_vocab)
|
matcher = Matcher(en_vocab)
|
||||||
get_is_fruit = lambda token: token.text in ("apple", "banana")
|
get_is_fruit = lambda token: token.text in ("apple", "banana")
|
||||||
|
|
|
@ -9,11 +9,6 @@ from spacy.tokens.underscore import Underscore
|
||||||
def test_issue4849():
|
def test_issue4849():
|
||||||
nlp = English()
|
nlp = English()
|
||||||
|
|
||||||
# reset the Underscore object because test_underscore has a lambda function that can't be pickled
|
|
||||||
Underscore.doc_extensions = {}
|
|
||||||
Underscore.span_extensions = {}
|
|
||||||
Underscore.token_extensions = {}
|
|
||||||
|
|
||||||
ruler = EntityRuler(
|
ruler = EntityRuler(
|
||||||
nlp, patterns=[
|
nlp, patterns=[
|
||||||
{"label": "PERSON", "pattern": 'joe biden', "id": 'joe-biden'},
|
{"label": "PERSON", "pattern": 'joe biden', "id": 'joe-biden'},
|
||||||
|
|
|
@ -33,11 +33,6 @@ class CustomPipe:
|
||||||
def test_issue4903():
|
def test_issue4903():
|
||||||
# ensures that this runs correctly and doesn't hang or crash on Windows / macOS
|
# ensures that this runs correctly and doesn't hang or crash on Windows / macOS
|
||||||
|
|
||||||
# reset the Underscore object because test_underscore has a lambda function that can't be pickled
|
|
||||||
Underscore.doc_extensions = {}
|
|
||||||
Underscore.span_extensions = {}
|
|
||||||
Underscore.token_extensions = {}
|
|
||||||
|
|
||||||
nlp = English()
|
nlp = English()
|
||||||
custom_component = CustomPipe()
|
custom_component = CustomPipe()
|
||||||
nlp.add_pipe(nlp.create_pipe("sentencizer"))
|
nlp.add_pipe(nlp.create_pipe("sentencizer"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user