Update factory import tests

This commit is contained in:
Matthew Honnibal 2025-05-21 15:39:19 +02:00
parent 43a9d37864
commit fe048275fb

View File

@ -8,45 +8,57 @@ import importlib
@pytest.mark.parametrize( @pytest.mark.parametrize(
"factory_name,original_module,compat_module", "factory_name,original_module,compat_module",
[ [
("make_tagger", "spacy.registrations", "spacy.pipeline.tagger"), ("make_tagger", "spacy.pipeline.factories", "spacy.pipeline.tagger"),
("make_sentencizer", "spacy.registrations", "spacy.pipeline.sentencizer"), ("make_sentencizer", "spacy.pipeline.factories", "spacy.pipeline.sentencizer"),
("make_ner", "spacy.registrations", "spacy.pipeline.ner"), ("make_ner", "spacy.pipeline.factories", "spacy.pipeline.ner"),
("make_parser", "spacy.registrations", "spacy.pipeline.dep_parser"), ("make_parser", "spacy.pipeline.factories", "spacy.pipeline.dep_parser"),
("make_tok2vec", "spacy.registrations", "spacy.pipeline.tok2vec"), ("make_tok2vec", "spacy.pipeline.factories", "spacy.pipeline.tok2vec"),
("make_spancat", "spacy.registrations", "spacy.pipeline.spancat"), ("make_spancat", "spacy.pipeline.factories", "spacy.pipeline.spancat"),
("make_spancat_singlelabel", "spacy.registrations", "spacy.pipeline.spancat"), (
("make_lemmatizer", "spacy.registrations", "spacy.pipeline.lemmatizer"), "make_spancat_singlelabel",
("make_entity_ruler", "spacy.registrations", "spacy.pipeline.entityruler"), "spacy.pipeline.factories",
("make_span_ruler", "spacy.registrations", "spacy.pipeline.span_ruler"), "spacy.pipeline.spancat",
),
("make_lemmatizer", "spacy.pipeline.factories", "spacy.pipeline.lemmatizer"),
("make_entity_ruler", "spacy.pipeline.factories", "spacy.pipeline.entityruler"),
("make_span_ruler", "spacy.pipeline.factories", "spacy.pipeline.span_ruler"),
( (
"make_edit_tree_lemmatizer", "make_edit_tree_lemmatizer",
"spacy.registrations", "spacy.pipeline.factories",
"spacy.pipeline.edit_tree_lemmatizer", "spacy.pipeline.edit_tree_lemmatizer",
), ),
( (
"make_attribute_ruler", "make_attribute_ruler",
"spacy.registrations", "spacy.pipeline.factories",
"spacy.pipeline.attributeruler", "spacy.pipeline.attributeruler",
), ),
("make_entity_linker", "spacy.registrations", "spacy.pipeline.entity_linker"), (
("make_textcat", "spacy.registrations", "spacy.pipeline.textcat"), "make_entity_linker",
("make_token_splitter", "spacy.registrations", "spacy.pipeline.functions"), "spacy.pipeline.factories",
("make_doc_cleaner", "spacy.registrations", "spacy.pipeline.functions"), "spacy.pipeline.entity_linker",
("make_morphologizer", "spacy.registrations", "spacy.pipeline.morphologizer"), ),
("make_senter", "spacy.registrations", "spacy.pipeline.senter"), ("make_textcat", "spacy.pipeline.factories", "spacy.pipeline.textcat"),
("make_span_finder", "spacy.registrations", "spacy.pipeline.span_finder"), ("make_token_splitter", "spacy.pipeline.factories", "spacy.pipeline.functions"),
("make_doc_cleaner", "spacy.pipeline.factories", "spacy.pipeline.functions"),
(
"make_morphologizer",
"spacy.pipeline.factories",
"spacy.pipeline.morphologizer",
),
("make_senter", "spacy.pipeline.factories", "spacy.pipeline.senter"),
("make_span_finder", "spacy.pipeline.factories", "spacy.pipeline.span_finder"),
( (
"make_multilabel_textcat", "make_multilabel_textcat",
"spacy.registrations", "spacy.pipeline.factories",
"spacy.pipeline.textcat_multilabel", "spacy.pipeline.textcat_multilabel",
), ),
("make_beam_ner", "spacy.registrations", "spacy.pipeline.ner"), ("make_beam_ner", "spacy.pipeline.factories", "spacy.pipeline.ner"),
("make_beam_parser", "spacy.registrations", "spacy.pipeline.dep_parser"), ("make_beam_parser", "spacy.pipeline.factories", "spacy.pipeline.dep_parser"),
("make_nn_labeller", "spacy.registrations", "spacy.pipeline.multitask"), ("make_nn_labeller", "spacy.pipeline.factories", "spacy.pipeline.multitask"),
# This one's special because the function was named make_span_ruler, so # This one's special because the function was named make_span_ruler, so
# the name in the registrations.py doesn't match the name we make the import hook # the name in the registrations.py doesn't match the name we make the import hook
# point to. We could make a test just for this but shrug # point to. We could make a test just for this but shrug
# ("make_future_entity_ruler", "spacy.registrations", "spacy.pipeline.span_ruler"), # ("make_future_entity_ruler", "spacy.pipeline.factories", "spacy.pipeline.span_ruler"),
], ],
) )
def test_factory_import_compatibility(factory_name, original_module, compat_module): def test_factory_import_compatibility(factory_name, original_module, compat_module):
@ -70,4 +82,3 @@ def test_factory_import_compatibility(factory_name, original_module, compat_modu
f"Factory {factory_name} imported from {original_module} is not the same object " f"Factory {factory_name} imported from {original_module} is not the same object "
f"as the one imported from {compat_module}" f"as the one imported from {compat_module}"
) )