MCPcopy
hub / github.com/explosion/spaCy / test_import_code

Function test_import_code

spacy/tests/test_misc.py:435–464  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

433
434
435def test_import_code():
436 code_str = """
437from spacy import Language
438
439class DummyComponent:
440 def __init__(self, vocab, name):
441 pass
442
443 def initialize(self, get_examples, *, nlp, dummy_param: int):
444 pass
445
446@Language.factory(
447 "dummy_component",
448)
449def make_dummy_component(
450 nlp: Language, name: str
451):
452 return DummyComponent(nlp.vocab, name)
453"""
454
455 with make_tempdir() as temp_dir:
456 code_path = os.path.join(temp_dir, "code.py")
457 with open(code_path, "w") as fileh:
458 fileh.write(code_str)
459
460 import_file("python_code", code_path)
461 config = {"initialize": {"components": {"dummy_component": {"dummy_param": 1}}}}
462 nlp = English.from_config(config)
463 nlp.add_pipe("dummy_component")
464 nlp.initialize()
465
466
467def test_to_ternary_int():

Callers

nothing calls this directly

Calls 5

import_fileFunction · 0.90
make_tempdirFunction · 0.85
from_configMethod · 0.80
add_pipeMethod · 0.80
initializeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…