2017-01-11 15:56:32 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
2015-06-07 18:53:14 +03:00
|
|
|
|
2017-01-13 04:23:50 +03:00
|
|
|
from io import StringIO, BytesIO
|
2017-01-13 01:38:47 +03:00
|
|
|
from pathlib import Path
|
2017-01-11 15:56:32 +03:00
|
|
|
import pytest
|
|
|
|
|
2017-05-29 23:14:31 +03:00
|
|
|
from .util import load_test_model
|
|
|
|
from ..tokens import Doc
|
|
|
|
from ..strings import StringStore
|
|
|
|
from .. import util
|
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
|
2017-05-13 16:37:54 +03:00
|
|
|
_languages = ['bn', 'da', 'de', 'en', 'es', 'fi', 'fr', 'he', 'hu', 'it', 'nb',
|
2017-05-29 23:14:31 +03:00
|
|
|
'nl', 'pl', 'pt', 'sv', 'xx']
|
2017-06-04 23:53:17 +03:00
|
|
|
_models = {'en': ['en_core_web_sm', 'en_depent_web_sm', 'en_core_web_md'],
|
2017-05-29 23:14:31 +03:00
|
|
|
'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
|
|
|
|
|
|
|
|
@pytest.fixture(params=_models['en'], scope="session")
|
|
|
|
def EN(request):
|
|
|
|
return load_test_model(request.param)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(params=_models['de'], scope="session")
|
|
|
|
def DE(request):
|
|
|
|
return load_test_model(request.param)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(params=_models['fr'], scope="session")
|
|
|
|
def FR(request):
|
|
|
|
return load_test_model(request.param)
|
2017-01-11 15:56:32 +03:00
|
|
|
|
|
|
|
|
2017-05-09 01:02:21 +03:00
|
|
|
@pytest.fixture(params=_languages)
|
2017-01-11 15:56:32 +03:00
|
|
|
def tokenizer(request):
|
2017-05-14 02:31:10 +03:00
|
|
|
lang = util.get_lang_class(request.param)
|
2017-01-11 15:56:32 +03:00
|
|
|
return lang.Defaults.create_tokenizer()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def en_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('en').Defaults.create_tokenizer()
|
2015-06-07 18:53:14 +03:00
|
|
|
|
2016-09-26 12:57:54 +03:00
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def en_vocab():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('en').Defaults.create_vocab()
|
2017-01-11 15:56:32 +03:00
|
|
|
|
|
|
|
|
2017-01-11 23:29:59 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def en_parser():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('en').Defaults.create_parser()
|
2017-05-09 01:02:21 +03:00
|
|
|
|
2017-01-11 23:29:59 +03:00
|
|
|
|
2017-04-06 19:48:45 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def es_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('es').Defaults.create_tokenizer()
|
2017-04-06 19:48:45 +03:00
|
|
|
|
2017-01-11 23:29:59 +03:00
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def de_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('de').Defaults.create_tokenizer()
|
2017-01-11 15:56:32 +03:00
|
|
|
|
|
|
|
|
2017-02-10 15:17:05 +03:00
|
|
|
@pytest.fixture(scope='module')
|
2017-01-24 12:55:02 +03:00
|
|
|
def fr_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('fr').Defaults.create_tokenizer()
|
2017-01-24 12:55:02 +03:00
|
|
|
|
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def hu_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('hu').Defaults.create_tokenizer()
|
2017-01-11 15:56:32 +03:00
|
|
|
|
2017-01-12 18:49:19 +03:00
|
|
|
|
2017-02-04 14:47:29 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def fi_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('fi').Defaults.create_tokenizer()
|
2017-02-04 14:47:29 +03:00
|
|
|
|
|
|
|
|
2017-02-04 17:21:34 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def sv_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('sv').Defaults.create_tokenizer()
|
2017-02-04 17:21:34 +03:00
|
|
|
|
|
|
|
|
2017-03-24 18:27:44 +03:00
|
|
|
@pytest.fixture
|
2017-03-05 04:11:26 +03:00
|
|
|
def bn_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('bn').Defaults.create_tokenizer()
|
2017-03-05 04:11:26 +03:00
|
|
|
|
2017-04-06 19:48:45 +03:00
|
|
|
|
|
|
|
@pytest.fixture
|
2017-03-24 18:27:44 +03:00
|
|
|
def he_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('he').Defaults.create_tokenizer()
|
2017-03-24 18:27:44 +03:00
|
|
|
|
2017-04-27 00:21:41 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def nb_tokenizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('nb').Defaults.create_tokenizer()
|
2017-05-09 01:02:21 +03:00
|
|
|
|
2017-03-24 18:27:44 +03:00
|
|
|
|
2017-01-12 17:05:40 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def stringstore():
|
|
|
|
return StringStore()
|
2017-01-11 15:56:32 +03:00
|
|
|
|
2017-01-12 18:49:19 +03:00
|
|
|
|
2017-01-12 23:56:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def en_entityrecognizer():
|
2017-05-14 02:31:10 +03:00
|
|
|
return util.get_lang_class('en').Defaults.create_entity()
|
2017-01-12 23:56:32 +03:00
|
|
|
|
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def text_file():
|
|
|
|
return StringIO()
|
|
|
|
|
2017-01-13 04:23:50 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def text_file_b():
|
|
|
|
return BytesIO()
|
|
|
|
|
2017-01-11 15:56:32 +03:00
|
|
|
|
2015-07-23 02:19:03 +03: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")
|
|
|
|
|
2017-05-29 23:10:16 +03:00
|
|
|
for lang in _languages + ['all']:
|
|
|
|
parser.addoption("--%s" % lang, action="store_true", help="Use %s models" % lang)
|
|
|
|
|
2015-07-23 02:19:03 +03:00
|
|
|
|
|
|
|
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)
|
2017-05-29 23:10:16 +03:00
|
|
|
|
|
|
|
# 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"):
|
|
|
|
pytest.skip()
|