This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allennlp test-install command (#1213)
* Add allennlp test-install command * Add back a newline that I accidentally removed * Add small test for _get_project_root * Fix typo in parens * Remove erroneous copy/paste * Add docs for test-install * Remove some unused imports in commands.__init__.py * Turn off notebook tests by default as well * Raise informative error message if jupyter not found * Move pytest, flaky, responses to requirements
- Loading branch information
1 parent
820cbfb
commit 356829d
Showing
9 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
The ``test-install`` subcommand verifies | ||
an installation by running the unit tests. | ||
.. code-block:: bash | ||
$ allennlp test-install --help | ||
usage: allennlp test-install [-h] [--run-all] | ||
[--include-package INCLUDE_PACKAGE] | ||
Test that installation works by running the unit tests. | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--run-all By default, we skip tests that are slow or download | ||
large files. This flag will run all tests. | ||
--include-package INCLUDE_PACKAGE | ||
additional packages to include | ||
""" | ||
|
||
import argparse | ||
import logging | ||
import os | ||
|
||
import pytest | ||
|
||
from allennlp.commands.subcommand import Subcommand | ||
|
||
logger = logging.getLogger(__name__) # pylint: disable=invalid-name | ||
|
||
class TestInstall(Subcommand): | ||
def add_subparser(self, name: str, parser: argparse._SubParsersAction) -> argparse.ArgumentParser: | ||
# pylint: disable=protected-access | ||
description = '''Test that installation works by running the unit tests.''' | ||
subparser = parser.add_parser( | ||
name, description=description, help='Run the unit tests.') | ||
|
||
subparser.add_argument('--run-all', action="store_true", | ||
help="By default, we skip tests that are slow " | ||
"or download large files. This flag will run all tests.") | ||
|
||
subparser.set_defaults(func=_run_test) | ||
|
||
return subparser | ||
|
||
|
||
def _get_project_root(): | ||
return os.path.abspath( | ||
os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), | ||
os.pardir, os.pardir)) | ||
|
||
|
||
def _run_test(args: argparse.Namespace): | ||
initial_working_dir = os.getcwd() | ||
project_root = _get_project_root() | ||
logger.info("Changing directory to %s", project_root) | ||
os.chdir(project_root) | ||
test_dir = os.path.join(project_root, "tests") | ||
logger.info("Running tests at %s", test_dir) | ||
if args.run_all: | ||
pytest.main([test_dir]) | ||
else: | ||
pytest.main([test_dir, '-k', 'not sniff_test and not notebooks_test']) | ||
# Change back to original working directory after running tests | ||
os.chdir(initial_working_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
allennlp.commands.test_install | ||
============================== | ||
|
||
.. automodule:: allennlp.commands.test_install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# pylint: disable=invalid-name,no-self-use | ||
import os | ||
|
||
from allennlp.common.testing import AllenNlpTestCase | ||
from allennlp.commands.test_install import _get_project_root | ||
|
||
|
||
class TestTestInstall(AllenNlpTestCase): | ||
def test_get_project_root(self): | ||
project_root = _get_project_root() | ||
assert os.path.exists(os.path.join(project_root, "tests")) | ||
assert os.path.exists(os.path.join(project_root, "LICENSE")) | ||
assert os.path.exists(os.path.join(project_root, "setup.py")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters