Skip to content

Commit

Permalink
test that at least one cli group is expected in custom commands file
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Dec 18, 2018
1 parent 761202b commit de39394
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bocadillo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _load_group(self, path: str):
groups = (val for val in ns.values() if isinstance(val, click.Group))
group = next(groups, None)
if group is None:
raise click.ClickException(
raise ValueError(
f"Expected at least one group in {path}, none found."
)
for name, cmd in group.commands.items():
Expand Down
16 changes: 14 additions & 2 deletions tests/test_cli_custom_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
from inspect import cleandoc

import pytest

from bocadillo.cli import create_cli
from tests.utils import env


def test_can_init_custom_commands(runner, tmpdir):
Expand Down Expand Up @@ -34,10 +37,19 @@ def hello():
)
)

os.environ["BOCA_CUSTOM_COMMANDS_FILE"] = str(boca_dot_py)
with env("BOCA_CUSTOM_COMMANDS_FILE", str(boca_dot_py)):
cli = create_cli()

cli = create_cli()
result = runner.invoke(cli, ["hello"])

assert result.exit_code == 0
assert result.output == "Hello!\n"


def test_at_least_one_group_is_expected(runner, tmpdir):
boca_dot_py = tmpdir.join("boca.py")
boca_dot_py.write("import click")

with env("BOCA_CUSTOM_COMMANDS_FILE", str(boca_dot_py)):
with pytest.raises(ValueError):
create_cli()

0 comments on commit de39394

Please sign in to comment.