Skip to content

Commit bb49ede

Browse files
Merge pull request #21 from wellcometrust/feature/tox
Use tox for testsing
2 parents bef7ee4 + e7d93d7 commit bb49ede

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ python:
44
- 3.7
55

66
install:
7-
- make virtualenv
87
- pip install -r requirements_test.txt
8+
- pip install tox-travis
99

1010
script:
11-
- make test
11+
- tox
1212

1313
cache:
1414
directories:
15-
- build
1615
- $HOME/.cache/pip
1716

1817
branches:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ $(test_artefacts):
145145

146146
.PHONY: test
147147
test: $(test_artefacts) test_embedding
148-
$(VIRTUALENV)/bin/pytest --disable-warnings --tb=line --cov=deep_reference_parser
148+
$(VIRTUALENV)/bin/tox
149149

150150
all: virtualenv model embedding test

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[pytest]
22
markers =
33
slow: marks tests as slow (deselect with '-m "not slow"')
4+
integration: Depends on downloading data from S3

tests/test_deep_reference_parser.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python3
22
# coding: utf-8
33

4+
import os
45
import shutil
56
import tempfile
67

78
import pytest
8-
from wasabi import msg
9-
109
from deep_reference_parser import DeepReferenceParser, get_config, load_tsv
10+
from deep_reference_parser.common import download_model_artefact
11+
from wasabi import msg
1112

1213
from .common import TEST_CFG, TEST_TSV_PREDICT, TEST_TSV_TRAIN
1314

@@ -17,12 +18,48 @@ def tmpdir(tmpdir_factory):
1718
return tmpdir_factory.mktemp("data")
1819

1920

20-
@pytest.fixture(scope="module")
21+
@pytest.fixture(scope="session")
2122
def cfg():
22-
return get_config(TEST_CFG)
23+
cfg = get_config(TEST_CFG)
24+
25+
artefacts = [
26+
"char2ind.pickle",
27+
"ind2label.pickle",
28+
"ind2word.pickle",
29+
"label2ind.pickle",
30+
"maxes.pickle",
31+
"weights.h5",
32+
"word2ind.pickle",
33+
]
34+
35+
S3_SLUG = cfg["data"]["s3_slug"]
36+
OUTPUT_PATH = cfg["build"]["output_path"]
37+
WORD_EMBEDDINGS = cfg["build"]["word_embeddings"]
38+
39+
for artefact in artefacts:
40+
with msg.loading(f"Could not find {artefact} locally, downloading..."):
41+
try:
42+
artefact = os.path.join(OUTPUT_PATH, artefact)
43+
download_model_artefact(artefact, S3_SLUG)
44+
msg.good(f"Found {artefact}")
45+
except:
46+
msg.fail(f"Could not download {S3_SLUG}{artefact}")
47+
48+
# Check on word embedding and download if not exists
49+
50+
WORD_EMBEDDINGS = cfg["build"]["word_embeddings"]
51+
52+
with msg.loading(f"Could not find {WORD_EMBEDDINGS} locally, downloading..."):
53+
try:
54+
download_model_artefact(WORD_EMBEDDINGS, S3_SLUG)
55+
msg.good(f"Found {WORD_EMBEDDINGS}")
56+
except:
57+
msg.fail(f"Could not download {S3_SLUG}{WORD_EMBEDDINGS}")
2358

59+
return cfg
2460

2561
@pytest.mark.slow
62+
@pytest.mark.integration
2663
def test_DeepReferenceParser_train(tmpdir, cfg):
2764
"""
2865
This test creates the artefacts that will be used in the next test
@@ -78,6 +115,7 @@ def test_DeepReferenceParser_train(tmpdir, cfg):
78115

79116

80117
@pytest.mark.slow
118+
@pytest.mark.integration
81119
def test_DeepReferenceParser_predict(tmpdir, cfg):
82120
"""
83121
You must run this test after the previous one, or it will fail

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tox]
2+
envlist = py37
3+
4+
[testenv]
5+
deps=-rrequirements_test.txt
6+
commands=pytest --tb=line --cov=deep_reference_parser --cov-append --disable-warnings

0 commit comments

Comments
 (0)