Skip to content

Commit

Permalink
use pytest markers to specify travis specific tests, remove custom te…
Browse files Browse the repository at this point in the history
…st mode system
  • Loading branch information
J38 committed Mar 5, 2019
1 parent 2bb26ca commit d22d3de
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ install:
- unzip corenlp.zip
- mv $CORENLP_VERSION $CORENLP_HOME
- mkdir ~/stanfordnlp_test
- export STANFORDNLP_TEST_MODE='BASIC'
- export STANFORDNLP_TEST_HOME=~/stanfordnlp_test
script:
- python -m pytest
- python -m pytest --markers travis
15 changes: 0 additions & 15 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
"""

import os
import pytest


# Environment Variables
# set this to specify test mode (run full set of tests, or smaller set on Travis)
TEST_MODE_VAR = 'STANFORDNLP_TEST_MODE'
# set this to specify working directory of tests
TEST_HOME_VAR = 'STANFORDNLP_TEST_HOME'

# Global Variables
# test working directory base name must be stanfordnlp_test
TEST_DIR_BASE_NAME = 'stanfordnlp_test'
# BASIC mode is a small set of tests to run on Travis
TEST_MODE_BASIC = 'BASIC'
# FULL mode runs all tests, this would typically be on a GPU machine with sufficient resources
TEST_MODE_FULL = 'FULL'

# check the working dir is set and compliant
assert os.getenv(TEST_HOME_VAR) is not None, \
Expand All @@ -28,13 +20,6 @@
f'Base name of test home dir must be: {TEST_DIR_BASE_NAME}'


def check_test_mode(tm):
""" Check if current test mode matches test mode for a module, skip if there is a mismatch """
if not os.getenv(TEST_MODE_VAR) == tm:
pytest.skip(f'Test module: test_run_pipeline only runs in FULL mode (set {TEST_MODE_VAR} to {tm})',
allow_module_level=True)


# langauge resources
LANGUAGE_RESOURCES = {}

Expand Down
8 changes: 8 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
"""
Tests that call a running CoreNLPClient.
"""
import pytest
import stanfordnlp.server as corenlp

# set the marker for this module
pytestmark = pytest.mark.travis

TEXT = "Chris wrote a simple sentence that he parsed with Stanford CoreNLP.\n"


def test_connect():
with corenlp.CoreNLPClient() as client:
client.ensure_alive()
assert client.is_active
assert client.is_alive()


def test_annotate():
with corenlp.CoreNLPClient(annotators="tokenize ssplit".split()) as client:
ann = client.annotate(TEXT)
assert corenlp.to_text(ann.sentence[0]) == TEXT[:-1]


def test_update():
with corenlp.CoreNLPClient(annotators="tokenize ssplit".split()) as client:
ann = client.annotate(TEXT)
ann = client.update(ann)
assert corenlp.to_text(ann.sentence[0]) == TEXT[:-1]


def test_tokensregex():
with corenlp.CoreNLPClient(annotators='tokenize ssplit ner depparse'.split(), timeout=60000) as client:
# Example pattern from: https://nlp.stanford.edu/software/tokensregex.shtml
Expand Down
4 changes: 1 addition & 3 deletions tests/test_english_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
Basic testing of the English pipeline
"""

import pytest
import stanfordnlp

from tests import *

# only run this test if TEST_MODE = FULL
check_test_mode(TEST_MODE_FULL)


def setup_module(module):
"""Set up resources for all tests in this module"""
Expand Down

0 comments on commit d22d3de

Please sign in to comment.