Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 9c51d6c

Browse files
authored
move test and fixtures to root level and simplify test-install command (#4264)
* simplify test-install command * update CHANGELOG * fix MANIFEST.in * move tests and fixtures to root level * fix archive fixture * update coverage configs
1 parent 65a146d commit 9c51d6c

File tree

259 files changed

+86
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+86
-205
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[run]
2-
omit = allennlp/tests/*
2+
omit = tests/*

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ per-file-ignores =
1818

1919
# tests don't have to respect
2020
# E731: do not assign a lambda expression, use a def
21-
allennlp/tests/**:E731
21+
tests/**:E731
2222

2323
# scripts don't have to respect
2424
# E402: imports not at top of file (because we mess with sys.path)

CHANGELOG.md

+8

MANIFEST.in

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ include LICENSE
22
include README.md
33
recursive-include allennlp *
44
recursive-include scripts *
5-
recursive-include training_config *.json
6-
recursive-include tutorials *
7-
global-exclude .DS_Store
8-
global-exclude __pycache__
5+
global-exclude .DS_Store *.py[cod]
6+
prune **/__pycache__
7+
prune **/.mypy_cache

Makefile

+10-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ version :
3838

3939
.PHONY : lint
4040
lint :
41-
flake8 ./scripts $(SRC)
41+
flake8 ./scripts ./tests $(SRC)
4242

4343
.PHONY : format
4444
format :
45-
black --check ./scripts $(SRC)
45+
black --check ./scripts ./tests $(SRC)
4646

4747
.PHONY : typecheck
4848
typecheck :
@@ -54,18 +54,18 @@ typecheck :
5454

5555
.PHONY : test
5656
test :
57-
pytest --color=yes -rf --durations=40 $(SRC) scripts/
57+
pytest --color=yes -rf --durations=40
5858

5959
.PHONY : test-with-cov
6060
test-with-cov :
6161
pytest --color=yes -rf --durations=40 \
6262
--cov-config=.coveragerc \
6363
--cov=$(SRC) \
64-
--cov-report=xml $(SRC) scripts/
64+
--cov-report=xml
6565

6666
.PHONY : gpu-test
6767
gpu-test :
68-
pytest --color=yes -v -rf -m gpu $(SRC)
68+
pytest --color=yes -v -rf -m gpu
6969

7070
#
7171
# Setup helpers
@@ -130,6 +130,11 @@ clean :
130130
rm -rf $(MD_DOCS_TGT)
131131
rm -rf $(MD_DOCS_API_ROOT)
132132
rm -f $(MD_DOCS_ROOT)*.md
133+
rm -rf .pytest_cache/
134+
rm -rf allennlp.egg-info/
135+
rm -rf dist/
136+
rm -rf build/
137+
find . | grep -E '(\.mypy_cache|__pycache__|\.pyc|\.pyo$$)' | xargs rm -rf
133138

134139
#
135140
# Docker helpers.

allennlp/commands/test_install.py

+18-41
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
"""
2-
The `test-install` subcommand verifies
3-
an installation by running the unit tests.
2+
The `test-install` subcommand provides a programmatic way to verify
3+
that AllenNLP has been successfully installed.
44
"""
55

66
import argparse
77
import logging
8-
import os
98
import pathlib
10-
import sys
119

12-
import pytest
1310
from overrides import overrides
11+
import torch
1412

1513
import allennlp
14+
from allennlp.common.util import import_module_and_submodules
1615
from allennlp.commands.subcommand import Subcommand
17-
from allennlp.common.util import pushd
16+
from allennlp.version import VERSION
1817

1918

2019
logger = logging.getLogger(__name__)
@@ -24,24 +23,11 @@
2423
class TestInstall(Subcommand):
2524
@overrides
2625
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
27-
28-
description = """Test that installation works by running the unit tests."""
26+
description = """Test that AllenNLP is installed correctly."""
2927
subparser = parser.add_parser(
30-
self.name, description=description, help="Run the unit tests."
31-
)
32-
33-
subparser.add_argument(
34-
"--run-all",
35-
action="store_true",
36-
help="By default, we skip tests that are slow "
37-
"or download large files. This flag will run all tests.",
38-
)
39-
subparser.add_argument(
40-
"-k", type=str, default=None, help="Limit tests by setting pytest -k argument"
28+
self.name, description=description, help="Test AllenNLP installation."
4129
)
42-
4330
subparser.set_defaults(func=_run_test)
44-
4531
return subparser
4632

4733

@@ -50,23 +36,14 @@ def _get_module_root():
5036

5137

5238
def _run_test(args: argparse.Namespace):
53-
module_parent = _get_module_root().parent
54-
logger.info("Changing directory to %s", module_parent)
55-
with pushd(module_parent):
56-
test_dir = os.path.join(module_parent, "allennlp")
57-
logger.info("Running tests at %s", test_dir)
58-
59-
if args.k:
60-
pytest_k = ["-k", args.k]
61-
pytest_m = ["-m", "not java"]
62-
if args.run_all:
63-
logger.warning("the argument '-k' overwrites '--run-all'.")
64-
elif args.run_all:
65-
pytest_k = []
66-
pytest_m = []
67-
else:
68-
pytest_k = ["-k", "not sniff_test"]
69-
pytest_m = ["-m", "not java"]
70-
71-
exit_code = pytest.main([test_dir, "--color=no"] + pytest_k + pytest_m)
72-
sys.exit(exit_code)
39+
# Make sure we can actually import the main modules without errors.
40+
import_module_and_submodules("allennlp.common")
41+
import_module_and_submodules("allennlp.data")
42+
import_module_and_submodules("allennlp.interpret")
43+
import_module_and_submodules("allennlp.models")
44+
import_module_and_submodules("allennlp.modules")
45+
import_module_and_submodules("allennlp.nn")
46+
import_module_and_submodules("allennlp.predictors")
47+
import_module_and_submodules("allennlp.training")
48+
logger.info("AllenNLP version %s installed to %s", VERSION, _get_module_root())
49+
logger.info("Cuda devices available: %s", torch.cuda.device_count())

allennlp/common/testing/test_case.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class AllenNlpTestCase:
1919
PROJECT_ROOT = (pathlib.Path(__file__).parent / ".." / ".." / "..").resolve()
2020
MODULE_ROOT = PROJECT_ROOT / "allennlp"
2121
TOOLS_ROOT = MODULE_ROOT / "tools"
22-
TESTS_ROOT = MODULE_ROOT / "tests"
23-
FIXTURES_ROOT = TESTS_ROOT / "fixtures"
22+
TESTS_ROOT = PROJECT_ROOT / "tests"
23+
FIXTURES_ROOT = PROJECT_ROOT / "test_fixtures"
2424

2525
def setup_method(self):
2626
logging.basicConfig(

allennlp/tests/data/dataset_readers/semantic_dependency_parsing.py

-109
This file was deleted.

allennlp/tests/fixtures/basic_classifier/experiment_from_archive.jsonnet

-14
This file was deleted.
Binary file not shown.

codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ coverage:
1111
changes: false
1212
comment: false
1313
ignore:
14-
- "allennlp/tests/"
14+
- "tests/"

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
testpaths = allennlp/tests/
2+
testpaths = tests/ scripts/tests/
33
python_classes = Test* *Test
44
log_format = %(asctime)s - %(levelname)s - %(name)s - %(message)s
55
log_level = DEBUG

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
author="Allen Institute for Artificial Intelligence",
4949
author_email="[email protected]",
5050
license="Apache",
51-
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
51+
packages=find_packages(
52+
exclude=["*.tests", "*.tests.*", "tests.*", "tests", "test_fixtures", "test_fixtures.*"]
53+
),
5254
install_requires=[
5355
"torch>=1.5.0,<1.6.0",
5456
"jsonnet>=0.10.0 ; sys.platform != 'win32'",
File renamed without changes.

allennlp/tests/fixtures/basic_classifier/common.jsonnet test_fixtures/basic_classifier/common.jsonnet

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
},
1515
"max_sequence_length": 400
1616
},
17-
"train_data_path": "allennlp/tests/fixtures/data/text_classification_json/imdb_corpus.jsonl",
18-
"validation_data_path": "allennlp/tests/fixtures/data/text_classification_json/imdb_corpus.jsonl",
17+
"train_data_path": "test_fixtures/data/text_classification_json/imdb_corpus.jsonl",
18+
"validation_data_path": "test_fixtures/data/text_classification_json/imdb_corpus.jsonl",
1919
"data_loader": {
2020

2121
"batch_sampler": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
local COMMON = import 'common.jsonnet';
2+
3+
{
4+
"dataset_reader": COMMON['dataset_reader'],
5+
"datasets_for_vocab_creation": ["train"],
6+
"train_data_path": "test_fixtures/data/text_classification_json/ag_news_corpus_fake_sentiment_labels.jsonl",
7+
"validation_data_path": "test_fixtures/data/text_classification_json/ag_news_corpus_fake_sentiment_labels.jsonl",
8+
"model": {
9+
"type": "from_archive",
10+
"archive_file": "test_fixtures/basic_classifier/serialization/model.tar.gz",
11+
},
12+
"data_loader": COMMON['data_loader'],
13+
"trainer": COMMON['trainer'],
14+
}
Binary file not shown.
File renamed without changes.
File renamed without changes.

allennlp/tests/fixtures/elmo/config/characters_token_embedder.json test_fixtures/elmo/config/characters_token_embedder.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
}
1313
}
1414
},
15-
"train_data_path": "allennlp/tests/fixtures/data/conll2003.txt",
16-
"validation_data_path": "allennlp/tests/fixtures/data/conll2003.txt",
15+
"train_data_path": "test_fixtures/data/conll2003.txt",
16+
"validation_data_path": "test_fixtures/data/conll2003.txt",
1717
"model": {
1818
"type": "simple_tagger",
1919
"text_field_embedder": {
@@ -24,8 +24,8 @@
2424
},
2525
"elmo": {
2626
"type": "elmo_token_embedder",
27-
"options_file": "allennlp/tests/fixtures/elmo/options.json",
28-
"weight_file": "allennlp/tests/fixtures/elmo/lm_weights.hdf5"
27+
"options_file": "test_fixtures/elmo/options.json",
28+
"weight_file": "test_fixtures/elmo/lm_weights.hdf5"
2929
}
3030
}
3131
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)