spaCy/spacy/tests/conftest.py

145 lines
3.3 KiB
Python
Raw Normal View History

2017-01-11 15:56:32 +03:00
# coding: utf-8
from __future__ import unicode_literals
2017-01-11 15:56:32 +03:00
import pytest
💫 Refactor test suite (#2568) ## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-07-25 00:38:44 +03:00
from spacy.util import get_lang_class
2017-01-11 15:56:32 +03:00
💫 Refactor test suite (#2568) ## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-07-25 00:38:44 +03:00
def pytest_addoption(parser):
parser.addoption("--slow", action="store_true", help="include slow tests")
💫 Refactor test suite (#2568) ## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-07-25 00:38:44 +03:00
def pytest_runtest_setup(item):
for opt in ["slow"]:
💫 Refactor test suite (#2568) ## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-07-25 00:38:44 +03:00
if opt in item.keywords and not item.config.getoption("--%s" % opt):
pytest.skip("need --%s option to run" % opt)
2017-06-05 03:26:13 +03:00
@pytest.fixture(scope="module")
2017-06-05 03:26:13 +03:00
def tokenizer():
return get_lang_class("xx").Defaults.create_tokenizer()
2017-01-11 15:56:32 +03:00
@pytest.fixture(scope="session")
2017-01-11 15:56:32 +03:00
def en_tokenizer():
return get_lang_class("en").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
2017-01-11 15:56:32 +03:00
def en_vocab():
return get_lang_class("en").Defaults.create_vocab()
2017-01-11 15:56:32 +03:00
@pytest.fixture(scope="session")
2017-10-07 01:38:51 +03:00
def en_parser(en_vocab):
nlp = get_lang_class("en")(en_vocab)
return nlp.create_pipe("parser")
2017-05-09 01:02:21 +03:00
2017-01-11 23:29:59 +03:00
@pytest.fixture(scope="session")
def es_tokenizer():
return get_lang_class("es").Defaults.create_tokenizer()
2017-01-11 23:29:59 +03:00
@pytest.fixture(scope="session")
2017-01-11 15:56:32 +03:00
def de_tokenizer():
return get_lang_class("de").Defaults.create_tokenizer()
2017-01-11 15:56:32 +03:00
@pytest.fixture(scope="session")
2017-01-24 12:55:02 +03:00
def fr_tokenizer():
return get_lang_class("fr").Defaults.create_tokenizer()
2017-01-24 12:55:02 +03:00
2017-06-05 03:09:27 +03:00
@pytest.fixture
2017-01-11 15:56:32 +03:00
def hu_tokenizer():
return get_lang_class("hu").Defaults.create_tokenizer()
2017-01-11 15:56:32 +03:00
2017-01-12 18:49:19 +03:00
@pytest.fixture(scope="session")
def fi_tokenizer():
return get_lang_class("fi").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
def ro_tokenizer():
return get_lang_class("ro").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
2017-08-20 08:17:14 +03:00
def id_tokenizer():
return get_lang_class("id").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
def sv_tokenizer():
return get_lang_class("sv").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
2017-03-05 04:11:26 +03:00
def bn_tokenizer():
return get_lang_class("bn").Defaults.create_tokenizer()
2017-03-05 04:11:26 +03:00
2017-10-31 17:50:13 +03:00
@pytest.fixture(scope="session")
2017-09-11 12:31:41 +03:00
def ga_tokenizer():
return get_lang_class("ga").Defaults.create_tokenizer()
2017-09-11 12:31:41 +03:00
@pytest.fixture(scope="session")
2017-03-24 18:27:44 +03:00
def he_tokenizer():
return get_lang_class("he").Defaults.create_tokenizer()
2017-03-24 18:27:44 +03:00
@pytest.fixture(scope="session")
2017-04-27 00:21:41 +03:00
def nb_tokenizer():
return get_lang_class("nb").Defaults.create_tokenizer()
2017-05-09 01:02:21 +03:00
@pytest.fixture(scope="session")
2017-07-03 16:43:06 +03:00
def da_tokenizer():
return get_lang_class("da").Defaults.create_tokenizer()
2017-03-24 18:27:44 +03:00
@pytest.fixture(scope="session")
2017-10-14 14:11:39 +03:00
def ja_tokenizer():
mecab = pytest.importorskip("MeCab")
return get_lang_class("ja").Defaults.create_tokenizer()
2017-10-14 14:11:39 +03:00
@pytest.fixture(scope="session")
2017-09-26 17:36:27 +03:00
def th_tokenizer():
2017-09-26 19:54:15 +03:00
pythainlp = pytest.importorskip("pythainlp")
return get_lang_class("th").Defaults.create_tokenizer()
2017-09-26 17:36:27 +03:00
@pytest.fixture(scope="session")
2017-12-01 17:04:32 +03:00
def tr_tokenizer():
return get_lang_class("tr").Defaults.create_tokenizer()
2017-12-01 17:04:32 +03:00
@pytest.fixture(scope="session")
def tt_tokenizer():
return get_lang_class("tt").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
def el_tokenizer():
return get_lang_class("el").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
def ar_tokenizer():
return get_lang_class("ar").Defaults.create_tokenizer()
2017-03-24 18:27:44 +03:00
@pytest.fixture(scope="session")
def ur_tokenizer():
return get_lang_class("ur").Defaults.create_tokenizer()
@pytest.fixture(scope="session")
def ru_tokenizer():
pymorphy = pytest.importorskip("pymorphy2")
return get_lang_class("ru").Defaults.create_tokenizer()