diff --git a/project/app.py b/project/app.py index 4e9ac38..1ae0a6d 100644 --- a/project/app.py +++ b/project/app.py @@ -1,8 +1,15 @@ -from click import command, option +import click -@command(context_settings={"help_option_names": ["-h", "--help"]}, help="Say hello") -@option("-n", "--name", default="World", help="Name", show_default=True) +@click.command(context_settings={"help_option_names": ["-h", "--help"]}, help="Say hello to a user.") +@click.option( + "-n", + "--name", + default="World", + help="The name of the person to greet.", + show_default=True, +) +@click.version_option() def main(name: str = "World"): """ Say hello to the given name. @@ -10,7 +17,7 @@ def main(name: str = "World"): Args: name: the name to be greeted """ - print(f"Hello {name}!") + click.secho(f"Hello {name}! 👋", fg="green", bold=True) if __name__ == "__main__": diff --git a/tests/test_app.py b/tests/test_app.py index c2a18e3..79971ed 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,9 +1,30 @@ -from pytest import main +from click.testing import CliRunner + +from project.app import main def test_main(): - pass + runner = CliRunner() + result = runner.invoke(main, ["--name", "Jules"]) + assert result.exit_code == 0 + assert "Hello Jules! 👋" in result.output + + +def test_main_default(): + runner = CliRunner() + result = runner.invoke(main) + assert result.exit_code == 0 + assert "Hello World! 👋" in result.output + + +def test_version(): + runner = CliRunner() + result = runner.invoke(main, ["--version"]) + assert result.exit_code == 0 + assert "version" in result.output.lower() if __name__ == "__main__": - main() + import pytest + + pytest.main()