mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-03 19:08:06 +03:00
Add test utils for temp file and temp dir
This commit is contained in:
parent
c8f4bed36f
commit
9692c98f57
|
@ -3,9 +3,14 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from ..tokens import Doc
|
from ..tokens import Doc
|
||||||
from ..attrs import ORTH, POS, HEAD, DEP
|
from ..attrs import ORTH, POS, HEAD, DEP
|
||||||
|
from ..compat import path2str
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import numpy
|
import numpy
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import contextlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
MODELS = {}
|
MODELS = {}
|
||||||
|
@ -19,6 +24,20 @@ def load_test_model(model):
|
||||||
return MODELS[model]
|
return MODELS[model]
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def make_tempfile(mode='r'):
|
||||||
|
f = tempfile.TemporaryFile(mode=mode)
|
||||||
|
yield f
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def make_tempdir():
|
||||||
|
d = Path(tempfile.mkdtemp())
|
||||||
|
yield d
|
||||||
|
shutil.rmtree(path2str(d))
|
||||||
|
|
||||||
|
|
||||||
def get_doc(vocab, words=[], pos=None, heads=None, deps=None, tags=None, ents=None):
|
def get_doc(vocab, words=[], pos=None, heads=None, deps=None, tags=None, ents=None):
|
||||||
"""Create Doc object from given vocab, words and annotations."""
|
"""Create Doc object from given vocab, words and annotations."""
|
||||||
pos = pos or [''] * len(words)
|
pos = pos or [''] * len(words)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user