2017-01-11 12:56:32 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
2015-06-07 15:53:14 +00:00
|
|
|
|
2017-01-11 12:56:32 +00:00
|
|
|
from ..tokens import Doc
|
2017-01-12 14:05:40 +00:00
|
|
|
from ..strings import StringStore
|
2017-01-12 22:38:55 +00:00
|
|
|
from ..lemmatizer import Lemmatizer
|
2017-01-11 12:56:32 +00:00
|
|
|
from ..attrs import ORTH, TAG, HEAD, DEP
|
2017-05-08 22:02:21 +00:00
|
|
|
from .. import util
|
2017-01-11 12:56:32 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2017-05-08 22:02:21 +00:00
|
|
|
_languages = ['bn', 'de', 'en', 'es', 'fi', 'fr', 'he', 'hu', 'it', 'nb', 'nl',
|
|
|
|
'pt', 'sv']
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2017-05-08 22:02:21 +00:00
|
|
|
@pytest.fixture(params=_languages)
|
2017-01-11 12:56:32 +00:00
|
|
|
def tokenizer(request):
|
2017-05-08 22:02:21 +00:00
|
|
|
lang = util.load_lang_class(request.param)
|
2017-01-11 12:56:32 +00:00
|
|
|
return lang.Defaults.create_tokenizer()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def en_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('en').Defaults.create_tokenizer()
|
2015-06-07 15:53:14 +00:00
|
|
|
|
2016-09-26 09:57:54 +00:00
|
|
|
|
2017-01-11 12:56:32 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def en_vocab():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('en').Defaults.create_vocab()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2017-01-11 20:29:59 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def en_parser():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('en').Defaults.create_parser()
|
|
|
|
|
2017-01-11 20:29:59 +00:00
|
|
|
|
2017-04-06 16:48:45 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def es_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('es').Defaults.create_tokenizer()
|
2017-04-06 16:48:45 +00:00
|
|
|
|
2017-01-11 20:29:59 +00:00
|
|
|
|
2017-01-11 12:56:32 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def de_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('de').Defaults.create_tokenizer()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2017-02-10 12:17:05 +00:00
|
|
|
@pytest.fixture(scope='module')
|
2017-01-24 09:55:02 +00:00
|
|
|
def fr_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('fr').Defaults.create_tokenizer()
|
2017-01-24 09:55:02 +00:00
|
|
|
|
|
|
|
|
2017-01-11 12:56:32 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def hu_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('hu').Defaults.create_tokenizer()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
2017-01-12 15:49:19 +00:00
|
|
|
|
2017-02-04 11:47:29 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def fi_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('fi').Defaults.create_tokenizer()
|
2017-02-04 11:47:29 +00:00
|
|
|
|
|
|
|
|
2017-02-04 14:21:34 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def sv_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('sv').Defaults.create_tokenizer()
|
2017-02-04 14:21:34 +00:00
|
|
|
|
|
|
|
|
2017-03-24 15:27:44 +00:00
|
|
|
@pytest.fixture
|
2017-03-05 01:11:26 +00:00
|
|
|
def bn_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('bn').Defaults.create_tokenizer()
|
2017-03-05 01:11:26 +00:00
|
|
|
|
2017-04-06 16:48:45 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
2017-03-24 15:27:44 +00:00
|
|
|
def he_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('he').Defaults.create_tokenizer()
|
2017-03-24 15:27:44 +00:00
|
|
|
|
2017-04-26 21:21:41 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def nb_tokenizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('nb').Defaults.create_tokenizer()
|
|
|
|
|
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-01-12 20:56:32 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def en_entityrecognizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('en').Defaults.create_entity()
|
2017-01-12 20:56:32 +00:00
|
|
|
|
|
|
|
|
2017-01-12 22:38:55 +00:00
|
|
|
@pytest.fixture
|
2017-03-17 00:48:00 +00:00
|
|
|
def lemmatizer():
|
2017-05-08 22:02:21 +00:00
|
|
|
return util.load_lang_class('en').Defaults.create_lemmatizer()
|
2017-01-12 22:38:55 +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
|
|
|
|
2017-01-12 21:03:07 +00:00
|
|
|
# only used for tests that require loading the models
|
|
|
|
# in all other cases, use specific instances
|
2015-06-07 15:53:14 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def EN():
|
2016-10-16 23:52:49 +00:00
|
|
|
return English()
|
2016-05-03 10:51:47 +00:00
|
|
|
|
2017-01-11 12:56:32 +00:00
|
|
|
|
2016-05-03 12:24:35 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2016-05-03 10:51:47 +00:00
|
|
|
def DE():
|
2016-10-16 23:52:49 +00:00
|
|
|
return German()
|
2015-07-22 23:19:03 +00:00
|
|
|
|
2017-04-27 09:52:14 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def FR():
|
|
|
|
return French()
|
|
|
|
|
2015-07-22 23:19:03 +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")
|
|
|
|
|
|
|
|
|
|
|
|
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)
|