Permalink
Please sign in to comment.
Browse files
Overhaul testing.
- Refactor to cleanup test_planemo, introduce higher-level concepts in new CliTestCase. - Add integration test for tool initialization and linting. - Bug fixes for tool linting overcovered with these commands. - Add integration test for initializing demo project and testing (cat.xml). - Add DOI to tool init (so we can have a lintable passing tool from init to test). - Add test for --help at root command. - Add test for --version at root command. - Update dev-requirements to include nose and coverage. - Add coveralls to travis testing.
- Loading branch information...
Showing
with
176 additions
and 24 deletions.
- +5 −1 .travis.yml
- +4 −0 dev-requirements.txt
- +9 −0 planemo/commands/cmd_tool_init.py
- +7 −0 planemo/tool_builder.py
- +4 −3 planemo_ext/galaxy/tools/lint.py
- +62 −0 tests/test_build_and_lint.py
- +11 −0 tests/test_init_and_test.py
- +22 −20 tests/test_planemo.py
- +52 −0 tests/test_utils.py
@@ -0,0 +1,62 @@ | |||
|
|||
from .test_utils import CliTestCase | |||
|
|||
|
|||
INIT_COMMAND = [ | |||
"tool_init", "--force", | |||
"--id", "seqtk_seq", | |||
"--name", "Convert to FASTA (seqtk)", | |||
"--requirement", "seqtk@1.0-r68", | |||
"--example_command", "seqtk seq -a 2.fastq > 2.fasta", | |||
"--example_input", "2.fastq", | |||
"--example_output", "2.fasta", | |||
"--test_case", | |||
"--help_text", "The help text.", | |||
"--doi", "10.1101/014043" | |||
] | |||
|
|||
|
|||
class BuildAndLintTestCase(CliTestCase): | |||
|
|||
def test_build_and_lint(self): | |||
with self._isolate(): | |||
self._check_exit_code(_init_command()) | |||
self._check_lint(exit_code=0) | |||
|
|||
def test_lint_fails_if_no_help(self): | |||
with self._isolate(): | |||
self._check_exit_code(_init_command(help_text=False)) | |||
self._check_lint(exit_code=1) | |||
|
|||
def test_lint_fails_if_no_test(self): | |||
with self._isolate(): | |||
self._check_exit_code(_init_command(test_case=False)) | |||
self._check_lint(exit_code=1) | |||
|
|||
def test_lint_fails_if_no_doi(self): | |||
with self._isolate(): | |||
self._check_exit_code(_init_command(doi=False)) | |||
self._check_lint(exit_code=1) | |||
|
|||
def _check_lint(self, exit_code=0): | |||
lint_cmd = ["lint", "--fail_level", "warn", "seqtk_seq.xml"] | |||
self._check_exit_code(lint_cmd, exit_code=exit_code) | |||
|
|||
|
|||
def _init_command(test_case=True, help_text=True, doi=True): | |||
command = [ | |||
"tool_init", "--force", | |||
"--id", "seqtk_seq", | |||
"--name", "Convert to FASTA (seqtk)", | |||
"--requirement", "seqtk@1.0-r68", | |||
"--example_command", "seqtk seq -a 2.fastq > 2.fasta", | |||
"--example_input", "2.fastq", | |||
"--example_output", "2.fasta" | |||
] | |||
if test_case: | |||
command.append("--test_case") | |||
if help_text: | |||
command.extend(["--help_text", "The help text."]) | |||
if doi: | |||
command.extend(["--doi", "10.1101/014043"]) | |||
return command |
@@ -0,0 +1,11 @@ | |||
from .test_utils import CliTestCase | |||
|
|||
|
|||
class InitAndTestTestCase(CliTestCase): | |||
|
|||
def test_init_and_test(self): | |||
with self._isolate(): | |||
init_cmd = ["project_init", "--template", "demo", "basic"] | |||
self._check_exit_code(init_cmd) | |||
test_cmd = ["test", "--install_galaxy", "basic/cat.xml"] | |||
self._check_exit_code(test_cmd) |
@@ -0,0 +1,52 @@ | |||
""" Provide abstractions over click testing of the | |||
app and unittest. | |||
""" | |||
from click.testing import CliRunner | |||
|
|||
from unittest import ( | |||
TestCase, | |||
main, | |||
) | |||
from planemo import cli | |||
|
|||
EXIT_CODE_MESSAGE = ("Planemo command [%s] resulted in unexpected exit code " | |||
"[%s], expected exit code [%s]]. Command output [%s]") | |||
|
|||
|
|||
# More information on testing click applications at following link. | |||
# http://click.pocoo.org/3/testing/#basic-testing | |||
class CliTestCase(TestCase): | |||
|
|||
def setUp(self): # noqa | |||
self._runner = CliRunner() | |||
|
|||
@property | |||
def _cli(self): | |||
return cli | |||
|
|||
def _isolate(self): | |||
return self._runner.isolated_filesystem() | |||
|
|||
def _invoke(self, command_list): | |||
planemo_cli = self._cli.planemo | |||
return self._runner.invoke(planemo_cli, command_list) | |||
|
|||
def _check_exit_code(self, command_list, exit_code=0): | |||
expected_exit_code = exit_code | |||
result = self._invoke(command_list) | |||
result_exit_code = result.exit_code | |||
if result_exit_code != expected_exit_code: | |||
message = EXIT_CODE_MESSAGE % ( | |||
" ".join(command_list), | |||
result_exit_code, | |||
expected_exit_code, | |||
result.output, | |||
) | |||
raise AssertionError(message) | |||
|
|||
|
|||
__all__ = [ | |||
"TestCase", | |||
"CliTestCase", | |||
"main", | |||
] |
0 comments on commit
0bd4ff0