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

This commit is contained in:
Sebastián Ramírez 2020-01-05 22:31:05 +01:00 committed by GitHub
commit ea0f2a6566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

51
tests/test_others.py Normal file
View file

@ -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