Skip to content

Commit

Permalink
Merge pull request #66 from algorandfoundation/help-output
Browse files Browse the repository at this point in the history
chore(tests): Added tests for help output
  • Loading branch information
robdmoore authored Dec 8, 2022
2 parents 00880bb + 798a2bd commit db399db
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/algokit/cli/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

@click.command(
"goal",
short_help="Run the Algorand goal CLI against the AlgoKit Sandbox",
short_help="Run the Algorand goal CLI against the AlgoKit Sandbox.",
context_settings={
"ignore_unknown_options": True,
},
)
@click.option(
"--console/--no-console",
help="Open a Bash console so you can execute multiple goal commands and/or interact with a filesystem",
help="Open a Bash console so you can execute multiple goal commands and/or interact with a filesystem.",
default=False,
)
@click.argument("goal_args", nargs=-1, type=click.UNPROCESSED)
Expand Down
4 changes: 2 additions & 2 deletions src/algokit/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _get_blessed_templates() -> dict[str, str]:
"--template",
type=DeferredChoice(lambda: list(_get_blessed_templates())),
default=None,
help="Name of an official template to use",
help="Name of an official template to use.",
)
@click.option(
"--template-url",
Expand All @@ -61,7 +61,7 @@ def _get_blessed_templates() -> dict[str, str]:
@click.option(
"--defaults",
default=None,
help="Automatically choose default answers without asking when creating this template",
help="Automatically choose default answers without asking when creating this template.",
is_flag=True,
)
@click.option(
Expand Down
12 changes: 6 additions & 6 deletions src/algokit/cli/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)


@click.group("sandbox", short_help="Manage the AlgoKit sandbox")
@click.group("sandbox", short_help="Manage the AlgoKit sandbox.")
def sandbox_group() -> None:
try:
compose_version_result = proc.run(
Expand Down Expand Up @@ -48,7 +48,7 @@ def sandbox_group() -> None:
proc.run(["docker", "version"], bad_return_code_error_message="Docker engine isn't running; please start it.")


@sandbox_group.command("start", short_help="Start the AlgoKit Sandbox")
@sandbox_group.command("start", short_help="Start the AlgoKit Sandbox.")
def start_sandbox() -> None:
sandbox = ComposeSandbox()
compose_file_status = sandbox.compose_file_status()
Expand All @@ -62,7 +62,7 @@ def start_sandbox() -> None:
sandbox.up()


@sandbox_group.command("stop", short_help="Stop the AlgoKit Sandbox")
@sandbox_group.command("stop", short_help="Stop the AlgoKit Sandbox.")
def stop_sandbox() -> None:
sandbox = ComposeSandbox()
compose_file_status = sandbox.compose_file_status()
Expand All @@ -72,7 +72,7 @@ def stop_sandbox() -> None:
sandbox.stop()


@sandbox_group.command("reset", short_help="Reset the AlgoKit Sandbox")
@sandbox_group.command("reset", short_help="Reset the AlgoKit Sandbox.")
@click.option(
"--update/--no-update",
default=True,
Expand All @@ -97,7 +97,7 @@ def reset_sandbox(update: bool) -> None: # noqa: FBT001
SERVICE_NAMES = ("algod", "indexer", "indexer-db")


@sandbox_group.command("status", short_help="Check the status of the AlgoKit Sandbox")
@sandbox_group.command("status", short_help="Check the status of the AlgoKit Sandbox.")
def sandbox_status() -> None:
sandbox = ComposeSandbox()
ps = sandbox.ps()
Expand Down Expand Up @@ -134,7 +134,7 @@ def sandbox_status() -> None:
@sandbox_group.command(
"console",
short_help="Run the Algorand goal CLI against the AlgoKit Sandbox via a Bash console"
+ " so you can execute multiple goal commands and/or interact with a filesystem",
+ " so you can execute multiple goal commands and/or interact with a filesystem.",
)
@click.pass_context
def sandbox_console(context: click.Context) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/algokit/core/log_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _set_force_styles_to(ctx: click.Context, _param: click.Option, value: bool |
is_flag=True,
callback=_set_verbose,
expose_value=False,
help="Enable logging of DEBUG messages to the console",
help="Enable logging of DEBUG messages to the console.",
)

color_option = click.option(
Expand All @@ -145,5 +145,5 @@ def _set_force_styles_to(ctx: click.Context, _param: click.Option, value: bool |
default=lambda: False if os.getenv("NO_COLOR") else None,
callback=_set_force_styles_to,
expose_value=False,
help="Force enable or disable of console output styling",
help="Force enable or disable of console output styling.",
)
10 changes: 8 additions & 2 deletions tests/goal/test_goal.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from subprocess import CompletedProcess

from pytest_mock import MockerFixture
from utils.app_dir_mock import AppDirs
from utils.approvals import verify
from utils.click_invoker import invoke
from utils.proc_mock import ProcMock


def test_goal_no_args(app_dir_mock: AppDirs, proc_mock: ProcMock):
def test_goal_help():
result = invoke("goal -h")

assert result.exit_code == 0
verify(result.output)


def test_goal_no_args(proc_mock: ProcMock, mocker: MockerFixture):
result = invoke("goal")

assert result.exit_code == 0
Expand Down
6 changes: 6 additions & 0 deletions tests/goal/test_goal.test_goal_help.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Usage: algokit goal [OPTIONS] [GOAL_ARGS]...

Options:
--console / --no-console Open a Bash console so you can execute multiple goal
commands and/or interact with a filesystem.
-h, --help Show this message and exit.
7 changes: 7 additions & 0 deletions tests/init/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def set_blessed_templates(mocker: MockerFixture):
}


def test_init_help():
result = invoke("init -h")

assert result.exit_code == 0
verify(result.output)


def test_init_no_interaction_required_no_git_no_network(
tmp_path_factory: TempPathFactory, mock_questionary_input: PipeInput
):
Expand Down
17 changes: 17 additions & 0 deletions tests/init/test_init.test_init_help.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Usage: algokit init [OPTIONS]

Initializes a new project from a template.

Options:
--name TEXT Name of the directory / repository to create.
--template [simple|beaker] Name of an official template to use.
--template-url URL URL to a git repo with a custom project template.
--accept-template-url Accept the specified template URL, acknowledging
the security implications of an unofficial
template.
--git / --no-git Initialise git repository in directory after
creation.
--defaults Automatically choose default answers without
asking when creating this template.
-a, --answer <key> <value> Answers key/value pairs to pass to the template.
-h, --help Show this message and exit.
9 changes: 9 additions & 0 deletions tests/sandbox/test_sandbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from approvaltests import verify # type: ignore
from utils.click_invoker import invoke


def test_sandbox_help():
result = invoke("sandbox -h")

assert result.exit_code == 0
verify(result.output)
13 changes: 13 additions & 0 deletions tests/sandbox/test_sandbox.test_sandbox_help.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Usage: algokit sandbox [OPTIONS] COMMAND [ARGS]...

Options:
-h, --help Show this message and exit.

Commands:
console Run the Algorand goal CLI against the AlgoKit Sandbox via a Bash
console so you can execute multiple goal commands and/or interact
with a filesystem.
reset Reset the AlgoKit Sandbox.
start Start the AlgoKit Sandbox.
status Check the status of the AlgoKit Sandbox.
stop Stop the AlgoKit Sandbox.
9 changes: 9 additions & 0 deletions tests/test_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from approvaltests import verify # type: ignore
from utils.click_invoker import invoke


def test_help():
result = invoke("-h")

assert result.exit_code == 0
verify(result.output)
15 changes: 15 additions & 0 deletions tests/test_root.test_help.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Usage: algokit [OPTIONS] COMMAND [ARGS]...

AlgoKit is your one-stop shop to develop applications on the Algorand
blockchain.

Options:
--version Show the version and exit.
-v, --verbose Enable logging of DEBUG messages to the console.
--color / --no-color Force enable or disable of console output styling.
-h, --help Show this message and exit.

Commands:
goal Run the Algorand goal CLI against the AlgoKit Sandbox.
init Initializes a new project.
sandbox Manage the AlgoKit sandbox.

0 comments on commit db399db

Please sign in to comment.