spaCy/spacy/tests/test_ty.py
Sofie Van Landeghem 5a38f79f18
Custom component types in spacy.ty (#9469)
* add custom protocols in spacy.ty

* add a test for the new types in spacy.ty

* import Example when type checking

* some type fixes

* put Protocol in compat

* revert update check back to hasattr

* runtime_checkable in compat as well
2021-10-21 15:31:06 +02:00

19 lines
748 B
Python

import spacy
from spacy import ty
def test_component_types():
nlp = spacy.blank("en")
tok2vec = nlp.create_pipe("tok2vec")
tagger = nlp.create_pipe("tagger")
entity_ruler = nlp.create_pipe("entity_ruler")
assert isinstance(tok2vec, ty.TrainableComponent)
assert isinstance(tagger, ty.TrainableComponent)
assert not isinstance(entity_ruler, ty.TrainableComponent)
assert isinstance(tok2vec, ty.InitializableComponent)
assert isinstance(tagger, ty.InitializableComponent)
assert isinstance(entity_ruler, ty.InitializableComponent)
assert isinstance(tok2vec, ty.ListenedToComponent)
assert not isinstance(tagger, ty.ListenedToComponent)
assert not isinstance(entity_ruler, ty.ListenedToComponent)