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
|
|
|
import pytest
|
2018-07-24 21:38:44 +00:00
|
|
|
from spacy.util import get_lang_class
|
2017-01-11 12:56:32 +00:00
|
|
|
|
2017-11-21 19:23:59 +00:00
|
|
|
|
2018-07-24 21:38:44 +00:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--slow", action="store_true", help="include slow tests")
|
2018-07-13 08:55:14 +00:00
|
|
|
|
2017-11-21 19:23:59 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2017-06-05 00:26:13 +00:00
|
|
|
def tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("xx").Defaults.create_tokenizer()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-01-11 12:56:32 +00:00
|
|
|
def en_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("en").Defaults.create_tokenizer()
|
2015-06-07 15:53:14 +00:00
|
|
|
|
2016-09-26 09:57:54 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-01-11 12:56:32 +00:00
|
|
|
def en_vocab():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("en").Defaults.create_vocab()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-10-06 22:38:51 +00:00
|
|
|
def en_parser(en_vocab):
|
2018-11-27 00:09:36 +00:00
|
|
|
nlp = get_lang_class("en")(en_vocab)
|
|
|
|
return nlp.create_pipe("parser")
|
2017-05-08 22:02:21 +00:00
|
|
|
|
2017-01-11 20:29:59 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-04-06 16:48:45 +00:00
|
|
|
def es_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("es").Defaults.create_tokenizer()
|
2017-04-06 16:48:45 +00:00
|
|
|
|
2017-01-11 20:29:59 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-01-11 12:56:32 +00:00
|
|
|
def de_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("de").Defaults.create_tokenizer()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-01-24 09:55:02 +00:00
|
|
|
def fr_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return 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():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("hu").Defaults.create_tokenizer()
|
2017-01-11 12:56:32 +00:00
|
|
|
|
2017-01-12 15:49:19 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-02-04 11:47:29 +00:00
|
|
|
def fi_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("fi").Defaults.create_tokenizer()
|
2017-02-04 11:47:29 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2018-05-12 13:20:04 +00:00
|
|
|
def ro_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("ro").Defaults.create_tokenizer()
|
2018-05-12 13:20:04 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-08-20 05:17:14 +00:00
|
|
|
def id_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("id").Defaults.create_tokenizer()
|
2017-02-04 11:47:29 +00:00
|
|
|
|
2017-10-14 11:11:18 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-02-04 14:21:34 +00:00
|
|
|
def sv_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("sv").Defaults.create_tokenizer()
|
2017-02-04 14:21:34 +00:00
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-03-05 01:11:26 +00:00
|
|
|
def bn_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("bn").Defaults.create_tokenizer()
|
2017-03-05 01:11:26 +00:00
|
|
|
|
2017-10-31 14:50:13 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-09-11 09:31:41 +00:00
|
|
|
def ga_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("ga").Defaults.create_tokenizer()
|
2017-09-11 09:31:41 +00:00
|
|
|
|
2017-04-06 16:48:45 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-03-24 15:27:44 +00:00
|
|
|
def he_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("he").Defaults.create_tokenizer()
|
2017-03-24 15:27:44 +00:00
|
|
|
|
2017-10-14 11:11:18 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-04-26 21:21:41 +00:00
|
|
|
def nb_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("nb").Defaults.create_tokenizer()
|
2017-05-08 22:02:21 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2017-07-03 13:43:06 +00:00
|
|
|
def da_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("da").Defaults.create_tokenizer()
|
|
|
|
|
2017-03-24 15:27:44 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-10-14 11:11:39 +00:00
|
|
|
def ja_tokenizer():
|
2018-07-13 08:55:14 +00:00
|
|
|
mecab = pytest.importorskip("MeCab")
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("ja").Defaults.create_tokenizer()
|
|
|
|
|
2017-10-14 11:11:39 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-09-26 14:36:27 +00:00
|
|
|
def th_tokenizer():
|
2017-09-26 16:54:15 +00:00
|
|
|
pythainlp = pytest.importorskip("pythainlp")
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("th").Defaults.create_tokenizer()
|
2017-09-26 14:36:27 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2017-12-01 14:04:32 +00:00
|
|
|
def tr_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("tr").Defaults.create_tokenizer()
|
|
|
|
|
2017-12-01 14:04:32 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2018-06-19 08:17:53 +00:00
|
|
|
def tt_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("tt").Defaults.create_tokenizer()
|
2018-06-19 08:17:53 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2018-07-10 11:48:38 +00:00
|
|
|
def el_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("el").Defaults.create_tokenizer()
|
|
|
|
|
2018-07-10 11:48:38 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2018-05-14 22:27:19 +00:00
|
|
|
def ar_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("ar").Defaults.create_tokenizer()
|
2017-03-24 15:27:44 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2018-06-22 09:14:03 +00:00
|
|
|
def ur_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
return get_lang_class("ur").Defaults.create_tokenizer()
|
|
|
|
|
2018-06-22 09:14:03 +00:00
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2017-11-21 19:23:59 +00:00
|
|
|
def ru_tokenizer():
|
2018-11-27 00:09:36 +00:00
|
|
|
pymorphy = pytest.importorskip("pymorphy2")
|
|
|
|
return get_lang_class("ru").Defaults.create_tokenizer()
|
2018-09-03 07:57:52 +00:00
|
|
|
|
2018-11-28 22:33:34 +00:00
|
|
|
|
2018-09-03 07:57:52 +00:00
|
|
|
def pytest_runtest_setup(item):
|
|
|
|
def getopt(opt):
|
|
|
|
# When using 'pytest --pyargs spacy' to test an installed copy of
|
|
|
|
# spacy, pytest skips running our pytest_addoption() hook. Later, when
|
|
|
|
# we call getoption(), pytest raises an error, because it doesn't
|
|
|
|
# recognize the option we're asking about. To avoid this, we need to
|
|
|
|
# pass a default value. We default to False, i.e., we act like all the
|
|
|
|
# options weren't given.
|
|
|
|
return item.config.getoption("--%s" % opt, False)
|
|
|
|
|
2018-11-28 22:33:34 +00:00
|
|
|
for opt in ["slow"]:
|
2018-09-03 07:57:52 +00:00
|
|
|
if opt in item.keywords and not getopt(opt):
|
|
|
|
pytest.skip("need --%s option to run" % opt)
|