spaCy/spacy/tests/conftest.py

154 lines
3.7 KiB
Python
Raw Normal View History

2017-01-11 12:56:32 +00:00
# coding: utf-8
from __future__ import unicode_literals
2017-01-13 01:23:50 +00:00
from io import StringIO, BytesIO
2017-01-12 22:38:47 +00:00
from pathlib import Path
2017-01-11 12:56:32 +00:00
import pytest
from .util import load_test_model
from ..tokens import Doc
from ..strings import StringStore
from .. import util
2017-01-11 12:56:32 +00:00
2017-08-20 05:17:14 +00:00
_languages = ['bn', 'da', 'de', 'en', 'es', 'fi', 'fr', 'he', 'hu', 'id',
'it', 'nb', 'nl', 'pl', 'pt', 'sv', 'xx']
2017-09-04 13:19:18 +00:00
_models = {'en': ['en_core_web_sm'],
'de': ['de_core_news_md'],
'fr': ['fr_depvec_web_lg'],
'xx': ['xx_ent_web_md']}
# only used for tests that require loading the models
# in all other cases, use specific instances
2017-06-05 00:09:27 +00:00
@pytest.fixture(params=_models['en'])
def EN(request):
return load_test_model(request.param)
2017-06-05 00:09:27 +00:00
@pytest.fixture(params=_models['de'])
def DE(request):
return load_test_model(request.param)
2017-06-05 00:09:27 +00:00
@pytest.fixture(params=_models['fr'])
def FR(request):
return load_test_model(request.param)
2017-01-11 12:56:32 +00:00
2017-06-05 00:26:13 +00:00
#@pytest.fixture(params=_languages)
#def tokenizer(request):
#lang = util.get_lang_class(request.param)
#return lang.Defaults.create_tokenizer()
@pytest.fixture
def tokenizer():
return util.get_lang_class('xx').Defaults.create_tokenizer()
2017-01-11 12:56:32 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-11 12:56:32 +00:00
def en_tokenizer():
return util.get_lang_class('en').Defaults.create_tokenizer()
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-11 12:56:32 +00:00
def en_vocab():
return util.get_lang_class('en').Defaults.create_vocab()
2017-01-11 12:56:32 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-11 20:29:59 +00:00
def en_parser():
return util.get_lang_class('en').Defaults.create_parser()
2017-05-08 22:02:21 +00:00
2017-01-11 20:29:59 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
def es_tokenizer():
return util.get_lang_class('es').Defaults.create_tokenizer()
2017-01-11 20:29:59 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-11 12:56:32 +00:00
def de_tokenizer():
return util.get_lang_class('de').Defaults.create_tokenizer()
2017-01-11 12:56:32 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-24 09:55:02 +00:00
def fr_tokenizer():
return util.get_lang_class('fr').Defaults.create_tokenizer()
2017-01-24 09:55:02 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-11 12:56:32 +00:00
def hu_tokenizer():
return util.get_lang_class('hu').Defaults.create_tokenizer()
2017-01-11 12:56:32 +00:00
2017-01-12 15:49:19 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
def fi_tokenizer():
return util.get_lang_class('fi').Defaults.create_tokenizer()
2017-08-20 05:17:14 +00:00
@pytest.fixture
def id_tokenizer():
return util.get_lang_class('id').Defaults.create_tokenizer()
2017-06-05 00:09:27 +00:00
@pytest.fixture
def sv_tokenizer():
return util.get_lang_class('sv').Defaults.create_tokenizer()
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-03-05 01:11:26 +00:00
def bn_tokenizer():
return util.get_lang_class('bn').Defaults.create_tokenizer()
2017-03-05 01:11:26 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-03-24 15:27:44 +00:00
def he_tokenizer():
return util.get_lang_class('he').Defaults.create_tokenizer()
2017-03-24 15:27:44 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-04-26 21:21:41 +00:00
def nb_tokenizer():
return util.get_lang_class('nb').Defaults.create_tokenizer()
2017-05-08 22:02:21 +00:00
2017-03-24 15:27:44 +00:00
2017-01-12 14:05:40 +00:00
@pytest.fixture
def stringstore():
return StringStore()
2017-01-11 12:56:32 +00:00
2017-01-12 15:49:19 +00:00
2017-06-05 00:09:27 +00:00
@pytest.fixture
2017-01-12 20:56:32 +00:00
def en_entityrecognizer():
return util.get_lang_class('en').Defaults.create_entity()
2017-01-12 20:56:32 +00:00
2017-01-11 12:56:32 +00:00
@pytest.fixture
def text_file():
return StringIO()
2017-01-13 01:23:50 +00:00
@pytest.fixture
def text_file_b():
return BytesIO()
2017-01-11 12:56:32 +00:00
def pytest_addoption(parser):
parser.addoption("--models", action="store_true",
help="include tests that require full models")
parser.addoption("--vectors", action="store_true",
help="include word vectors tests")
parser.addoption("--slow", action="store_true",
help="include slow tests")
for lang in _languages + ['all']:
parser.addoption("--%s" % lang, action="store_true", help="Use %s models" % lang)
def pytest_runtest_setup(item):
for opt in ['models', 'vectors', 'slow']:
if opt in item.keywords and not item.config.getoption("--%s" % opt):
pytest.skip("need --%s option to run" % opt)
# Check if test is marked with models and has arguments set, i.e. specific
# language. If so, skip test if flag not set.
if item.get_marker('models'):
for arg in item.get_marker('models').args:
if not item.config.getoption("--%s" % arg) and not item.config.getoption("--all"):
2017-06-05 00:09:27 +00:00
pytest.skip("need --%s or --all option to run" % arg)