Add test utils for temp file and temp dir

This commit is contained in:
ines 2017-06-02 10:56:09 +02:00
parent c8f4bed36f
commit 9692c98f57

View File

@ -3,9 +3,14 @@ from __future__ import unicode_literals
from ..tokens import Doc
from ..attrs import ORTH, POS, HEAD, DEP
from ..compat import path2str
import pytest
import numpy
import tempfile
import shutil
import contextlib
from pathlib import Path
MODELS = {}
@ -19,6 +24,20 @@ def load_test_model(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):
"""Create Doc object from given vocab, words and annotations."""
pos = pos or [''] * len(words)