Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tools test #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,10 @@ mamba create -n pyclient \
conda activate pyclient
```

- Install all non-conda dependencies via pip

```bash
pip install -r pip-requirements.txt
```

- Install `pyclient` (in developer mode)

```bash
python setup.py develop
pip install --editable .
```

- Validate the install via the help message
Expand All @@ -79,6 +73,12 @@ client-tools -h
snakemake --snakefile src/snakemake/hello_world.smk -j 1
```

- Run the precommit script (unit tests, linting, code-style, type checking)

```bash
bash scripts/precommit.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bash scripts/precommit.sh
bash ci/precommit.sh

```

[fulcrum-genomics-link]: https://www.fulcrumgenomics.com
[conda-link]: https://docs.conda.io/projects/conda/en/latest/user-guide/install/

18 changes: 18 additions & 0 deletions src/python/pyclient/tools/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Testing utilities for :module:`~pyclient.tools`"""

import pytest


def _to_name(tool) -> str: # type: ignore
"""Gives the tool name for a function by taking the function name and replacing
underscores with hyphens."""
return tool.__name__.replace("_", "-")


def test_tool_funcs(tool, main) -> None: # type: ignore
name = _to_name(tool)
argv = [name, "-h"]
with pytest.raises(SystemExit) as e:
main(argv=argv)
assert e.type == SystemExit
assert e.value.code == 0 # code should be 0 for help
31 changes: 31 additions & 0 deletions src/python/pyclient/tools/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for :module:`~pyclient.tools.__main__
Motivation
~~~~~~~~~~
The idea is to run help on the main tools method (`-h`) as well as on
each tool (ex. `tool-name -h`). This should force :module:`~defopt`
to parse the docstring for the method. Since :module:`~defopt` uses
:module:`~argparse` underneath, `SystemExit`s are raised, which are
different than regular `Exceptions`. The exit code returned by help
(the usage) is 0. An improperly formatted docstring throws a
:class:`NotImplementedException`. We add a few tests below to show
this.
"""

import pytest
from pyclient.tools.__main__ import TOOLS
from pyclient.tools.__main__ import main
from pyclient.tools.tests import test_tool_funcs as _test_tool_funcs


def test_tools_help() -> None:
"""Tests that running pyclient-tools with -h exits OK"""
argv = ["-h"]
with pytest.raises(SystemExit) as e:
main(argv=argv)
assert e.type == SystemExit
assert e.value.code == 0 # code should be 0 for help


@pytest.mark.parametrize("tool", TOOLS)
def test_tool_funcs(tool) -> None: # type: ignore
_test_tool_funcs(tool, main)