Skip to content

Commit 526a5d9

Browse files
authored
Increase cli test coverage (#533)
* fix typo, add test_install_command_value_error * fix typo, parametrize to test correct behaviour when atlas name is None for multiple commands * add test_cli_incorrect_command * add test_cli_list * fix test_update_command * add docstring
1 parent 2920d3c commit 526a5d9

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

brainglobe_atlasapi/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def bg_cli(
4141
if atlas_name is None:
4242
raise ValueError(
4343
'No atlas named passed with command "install". Use the "-a"\
44-
argument to pass an atls name'
44+
argument to pass an atlas name'
4545
)
4646
return install_atlas(atlas_name=atlas_name)
4747

4848
elif command == "update": # update installed atlas
4949
if atlas_name is None:
5050
raise ValueError(
5151
'No atlas named passed with command "update". Use the "-a"\
52-
argument to pass an atls name'
52+
argument to pass an atlas name'
5353
)
5454
return update_atlas(atlas_name, force=force)
5555

tests/atlasapi/test_cli.py

+38-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from click.testing import CliRunner
23

34
from brainglobe_atlasapi import cli, config
@@ -22,10 +23,12 @@ def test_config_cli():
2223

2324

2425
def test_update_command():
25-
runner = CliRunner()
26-
27-
# Test printing of config file:
28-
runner.invoke(cli.bg_cli, ["config", "-a", "example_mouse_100um", "-f"])
26+
"""Test update command."""
27+
update_atlas = CliRunner().invoke(
28+
cli.bg_cli, ["update", "-a", "example_mouse_100um", "-f"]
29+
)
30+
expected_output = "updating example_mouse_100um\nDownloading..."
31+
assert expected_output in update_atlas.output
2932

3033

3134
def test_install_command():
@@ -35,8 +38,35 @@ def test_install_command():
3538
runner.invoke(cli.bg_cli, ["install", "-a", "example_mouse_100um"])
3639

3740

38-
def test_list_command():
39-
runner = CliRunner()
41+
def test_cli_list():
42+
"""Test list command."""
43+
atlases_table = CliRunner().invoke(cli.bg_cli, ["list", "--show"])
44+
assert atlases_table.exit_code == 0
45+
assert "nadkarni_mri_mouselemur_91um" in atlases_table.output
4046

41-
# Test printing of config file:
42-
runner.invoke(cli.bg_cli, ["list", "s"])
47+
48+
@pytest.mark.parametrize(
49+
["command"], [pytest.param("install"), pytest.param("update")]
50+
)
51+
def test_atlas_name_is_none_value_error(command):
52+
"""Test whether command without atlas name raises ValueError."""
53+
with pytest.raises(
54+
ValueError,
55+
match=(
56+
f'No atlas named passed with command "{command}". Use the "-a"'
57+
r"\s+argument to pass an atlas name"
58+
),
59+
):
60+
CliRunner().invoke(
61+
cli.bg_cli, [command, "-a", None], catch_exceptions=False
62+
)
63+
64+
65+
def test_cli_incorrect_command():
66+
"""Test whether incorrect "flibble" command raises ValueError."""
67+
command = "flibble"
68+
with pytest.raises(
69+
ValueError,
70+
match=f'Invalid command {command}. use "brainglobe -h for more info."',
71+
):
72+
CliRunner().invoke(cli.bg_cli, [command], catch_exceptions=False)

0 commit comments

Comments
 (0)