diff --git a/.travis.yml b/.travis.yml index 166780b..44a51c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ script: if [ "$JYTHON" == "true" ]; then py.test else - py.test --cov=pyoracc --cov-report xml + py.test --cov=pyoracc --cov-report xml --runslow fi - pep8 --exclude=parsetab.py . diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..a1eaf23 --- /dev/null +++ b/conftest.py @@ -0,0 +1,6 @@ +import pytest + + +def pytest_addoption(parser): + parser.addoption("--runslow", action="store_true", + help="run slow tests") diff --git a/pyoracc/test/fixtures/__init__.py b/pyoracc/test/fixtures/__init__.py index ef5ec4f..7a64109 100644 --- a/pyoracc/test/fixtures/__init__.py +++ b/pyoracc/test/fixtures/__init__.py @@ -16,6 +16,23 @@ def tiny_corpus(): return os.path.join(os.path.dirname(here), 'tiny_corpus') +def sample_corpus(): + return os.path.join(os.path.dirname(here), 'sample_corpus') + + +def whole_corpus(): + """ + Return the path to the full oracc corpus. This is not bundled with + pyoracc and only works if the environmental variable oracc_corpus_path + is set to the correct directory. + """ + try: + oracc_corpus_path = os.environ['oracc_corpus_path'] + except KeyError: + oracc_corpus_path = None + return oracc_corpus_path + + def anzu(): return sample_file("anzu") diff --git a/pyoracc/test/model/test_corpus.py b/pyoracc/test/model/test_corpus.py index a3ed1e6..f1118a6 100644 --- a/pyoracc/test/model/test_corpus.py +++ b/pyoracc/test/model/test_corpus.py @@ -1,9 +1,35 @@ +import pytest + from ...model.corpus import Corpus -from ..fixtures import tiny_corpus +from ..fixtures import tiny_corpus, sample_corpus, whole_corpus + + +slow = pytest.mark.skipif( + not pytest.config.getoption("--runslow"), + reason="need --runslow option to run" +) def test_tiny(): corpus = Corpus(source=tiny_corpus()) assert corpus.successes == 1 assert corpus.failures == 1 + + +@slow +def test_sample(): + corpus = Corpus(source=sample_corpus()) + assert corpus.successes == 36 + assert corpus.failures == 3 + + +@pytest.mark.skipif(not whole_corpus(), + reason="Need to set oracc_corpus_path to point " + "to the whole corpus, which is not bundled with " + "pyoracc") +@slow +def test_whole(): + corpus = Corpus(source=whole_corpus()) + assert corpus.successes == 2474 + assert corpus.failures == 394