From 3efee0a55103114548013fd7111bf5d9dd0c0bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 5 Jan 2020 22:20:54 +0100 Subject: [PATCH] :white_check_mark: Add 4 extra tests for edge cases --- tests/test_others.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/test_others.py diff --git a/tests/test_others.py b/tests/test_others.py new file mode 100644 index 0000000..1be59b9 --- /dev/null +++ b/tests/test_others.py @@ -0,0 +1,51 @@ +from typing import Optional + +import typer +from typer.main import solve_typer_info_defaults, solve_typer_info_help +from typer.models import TyperInfo +from typer.testing import CliRunner + +runner = CliRunner() + + +def test_optional(): + app = typer.Typer() + + @app.command() + def opt(user: Optional[str] = None): + if user: + typer.echo(f"User: {user}") + else: + typer.echo("No user") + + result = runner.invoke(app) + assert result.exit_code == 0 + assert "No user" in result.output + + result = runner.invoke(app, ["--user", "Camila"]) + assert result.exit_code == 0 + assert "User: Camila" in result.output + + +def test_no_type(): + app = typer.Typer() + + @app.command() + def no_type(user): + typer.echo(f"User: {user}") + + result = runner.invoke(app, ["Camila"]) + assert result.exit_code == 0 + assert "User: Camila" in result.output + + +def test_help_from_info(): + # Mainly for coverage/completeness + value = solve_typer_info_help(TyperInfo()) + assert value is None + + +def test_defaults_from_info(): + # Mainly for coverage/completeness + value = solve_typer_info_defaults(TyperInfo()) + assert value