mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-10 19:57:17 +03:00
Update and add test
This commit is contained in:
parent
8ed788660b
commit
21176c69b0
|
@ -451,13 +451,27 @@ def test_pipe_factories_from_source_config():
|
|||
assert config["arg"] == "world"
|
||||
|
||||
|
||||
def test_pipe_factories_decorator_idempotent():
|
||||
class PipeFactoriesIdempotent:
|
||||
def __init__(self, nlp, name):
|
||||
...
|
||||
|
||||
def __call__(self, doc):
|
||||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"i,func,func2",
|
||||
[
|
||||
(0, lambda nlp, name: lambda doc: doc, lambda doc: doc),
|
||||
(1, PipeFactoriesIdempotent, PipeFactoriesIdempotent(None, None)),
|
||||
],
|
||||
)
|
||||
def test_pipe_factories_decorator_idempotent(i, func, func2):
|
||||
"""Check that decorator can be run multiple times if the function is the
|
||||
same. This is especially relevant for live reloading because we don't
|
||||
want spaCy to raise an error if a module registering components is reloaded.
|
||||
"""
|
||||
name = "test_pipe_factories_decorator_idempotent"
|
||||
func = lambda nlp, name: lambda doc: doc
|
||||
name = f"test_pipe_factories_decorator_idempotent_{i}"
|
||||
for i in range(5):
|
||||
Language.factory(name, func=func)
|
||||
nlp = Language()
|
||||
|
@ -466,7 +480,6 @@ def test_pipe_factories_decorator_idempotent():
|
|||
# Make sure it also works for component decorator, which creates the
|
||||
# factory function
|
||||
name2 = f"{name}2"
|
||||
func2 = lambda doc: doc
|
||||
for i in range(5):
|
||||
Language.component(name2, func=func2)
|
||||
nlp = Language()
|
||||
|
|
|
@ -930,7 +930,7 @@ def is_same_func(func1: Callable, func2: Callable) -> bool:
|
|||
"""
|
||||
if not callable(func1) or not callable(func2):
|
||||
return False
|
||||
if not hasattr(func1,"__qualname__") or not hasattr(func2,"__qualname__"):
|
||||
if not hasattr(func1, "__qualname__") or not hasattr(func2, "__qualname__"):
|
||||
return False
|
||||
same_name = func1.__qualname__ == func2.__qualname__
|
||||
same_file = inspect.getfile(func1) == inspect.getfile(func2)
|
||||
|
|
Loading…
Reference in New Issue
Block a user