Skip to content
Myr

:white_check_mark: Add extra tests for edge cases that don't belong on docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parents bcdcfce, 3efee0a · Browse files · 1 file+51 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+51 added−0 removed

  • tests:+51 added−0 removed

1 file+51 added−0 removed

added:tests/test_others.py+51 added
1from typing import Optional23import typer4from typer.main import solve_typer_info_defaults, solve_typer_info_help5from typer.models import TyperInfo6from typer.testing import CliRunner78runner = CliRunner()91011def test_optional():12 app = typer.Typer()1314 @app.command()15 def opt(user: Optional[str] = None):16 if user:17 typer.echo(f"User: {user}")18 else:19 typer.echo("No user")2021 result = runner.invoke(app)22 assert result.exit_code == 023 assert "No user" in result.output2425 result = runner.invoke(app, ["--user", "Camila"])26 assert result.exit_code == 027 assert "User: Camila" in result.output282930def test_no_type():31 app = typer.Typer()3233 @app.command()34 def no_type(user):35 typer.echo(f"User: {user}")3637 result = runner.invoke(app, ["Camila"])38 assert result.exit_code == 039 assert "User: Camila" in result.output404142def test_help_from_info():43 # Mainly for coverage/completeness44 value = solve_typer_info_help(TyperInfo())45 assert value is None464748def test_defaults_from_info():49 # Mainly for coverage/completeness50 value = solve_typer_info_defaults(TyperInfo())51 assert value