✅ Add extra tests for edge cases that don't belong on docs
This commit is contained in:
commit
ea0f2a6566
1 changed files with 51 additions and 0 deletions
51
tests/test_others.py
Normal file
51
tests/test_others.py
Normal 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
|
Loading…
Reference in a new issue