()
| 433 | |
| 434 | |
| 435 | def test_import_code(): |
| 436 | code_str = """ |
| 437 | from spacy import Language |
| 438 | |
| 439 | class 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 | ) |
| 449 | def 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 | |
| 467 | def test_to_ternary_int(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…