Use make_tempdir instead

This commit is contained in:
Adriane Boyd 2021-03-01 17:54:14 +01:00
parent e9f7f9a4bc
commit 0efb7413f9
2 changed files with 6 additions and 12 deletions

View File

@ -17,7 +17,7 @@ from spacy.schemas import ConfigSchemaTraining
from thinc.api import get_current_ops, NumpyOps, CupyOps from thinc.api import get_current_ops, NumpyOps, CupyOps
from .util import get_random_doc, make_named_tempfile from .util import get_random_doc, make_tempdir
@pytest.fixture @pytest.fixture
@ -369,11 +369,12 @@ def make_dummy_component(
return DummyComponent(nlp.vocab, name) return DummyComponent(nlp.vocab, name)
""" """
with make_named_tempfile(mode="w", suffix=".py") as fileh: with make_tempdir() as temp_dir:
fileh.write(code_str) code_path = os.path.join(temp_dir, "code.py")
fileh.flush() with open(code_path, "w") as fileh:
fileh.write(code_str)
import_file("python_code", fileh.name) import_file("python_code", code_path)
config = {"initialize": {"components": {"dummy_component": {"dummy_param": 1}}}} config = {"initialize": {"components": {"dummy_component": {"dummy_param": 1}}}}
nlp = English.from_config(config) nlp = English.from_config(config)
nlp.add_pipe("dummy_component") nlp.add_pipe("dummy_component")

View File

@ -14,13 +14,6 @@ def make_tempfile(mode="r"):
f.close() f.close()
@contextlib.contextmanager
def make_named_tempfile(mode="r", suffix=None):
f = tempfile.NamedTemporaryFile(mode=mode, suffix=suffix)
yield f
f.close()
def get_batch(batch_size): def get_batch(batch_size):
vocab = Vocab() vocab = Vocab()
docs = [] docs = []