-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the CLI scripts: - Adapt and transfer the contents of the `test_scripts.py` test script to a more modern and compact approach that uses the `pytest` `pytest-console-script` plugin and that does not require fiddling with the location of the files. This allows to test that the CLI scripts are installed appropriately/called using the names defined in the `pyproject.toml` `project.scripts` section. - Split the tests into two different files following the scripts being tested: `tract_math` and `tract_querier`. - Remove the `test_scripts.py` file. Add the `pytest-console-script` dependency so that the scripts can be called when executing `pytest`. Convert the `output.values()` ordered dictionary values to a list prior to slicing in `decorator.py`. Fixes: ``` "/src/tract_querier/scripts/cli_tract_math.py", line 109, in main\n operations[args.operation] (\n File "/src/tract_querier/tract_querier/tract_math/decorator.py", line 148, in wrapper\n process_output(func(*option_and_args))\n File "/src/tract_querier/tract_querier/tract_math/decorator.py", line 199, in process_output\n first_value = output.values()[0]\n TypeError: \'odict_values\' object is not subscriptable\n') ``` raised locally when running the script tests.
- Loading branch information
1 parent
afb437b
commit 9d30828
Showing
5 changed files
with
50 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ doc = [ | |
test = [ | ||
"coverage", | ||
"pytest", | ||
"pytest-console-scripts", | ||
] | ||
|
||
[project.urls] | ||
|
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import re | ||
|
||
from tract_querier.tests import datasets | ||
|
||
|
||
def test_help_option(script_runner): | ||
ret = script_runner.run("tract_math", "--help") | ||
assert ret.success | ||
|
||
|
||
def test_tract_math_count(script_runner): | ||
test_data = datasets.TestDataSet() | ||
tract_file = test_data.files["tract_file"] | ||
ret = script_runner.run("tract_math", tract_file, "count") | ||
assert re.search('[^0-9]6783[^0-9]', ret.stdout) is not None | ||
assert ret.success |
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,29 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
from os import path | ||
|
||
from tract_querier.tests import datasets | ||
|
||
|
||
def test_help_option(script_runner): | ||
ret = script_runner.run("tract_querier", "--help") | ||
assert ret.success | ||
|
||
|
||
def test_tract_querier_query(script_runner): | ||
test_data = datasets.TestDataSet() | ||
atlas_file = test_data.files["atlas_file"] | ||
query_uf_file = test_data.files["query_uf_file"] | ||
tract_file = test_data.files["tract_file"] | ||
output_prefix = test_data.dirname + "/test" | ||
|
||
ret = script_runner.run("tract_querier", "-a", atlas_file,"-t", tract_file, "-q", query_uf_file, "-o", output_prefix) | ||
tract_fname_end = "_uncinate.left.trk" | ||
assert "uncinate.left: 000102" in ret.stdout | ||
assert "uncinate.right: 000000" in ret.stdout | ||
assert path.exists(output_prefix + tract_fname_end) | ||
assert ret.success | ||
if path.exists(output_prefix + tract_fname_end): | ||
os.remove(output_prefix + tract_fname_end) |
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