Coverage for tests / test_types.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1from enum import Enum 1abcdefgh
3import typer 1abcdefgh
4from typer.testing import CliRunner 1abcdefgh
6app = typer.Typer(context_settings={"token_normalize_func": str.lower}) 1abcdefgh
9class User(str, Enum): 1abcdefgh
10 rick = "Rick" 1abcdefgh
11 morty = "Morty" 1abcdefgh
14@app.command() 1abcdefgh
15def hello(name: User = User.rick) -> None: 1abcdefgh
16 print(f"Hello {name.value}!") 1abcdefgh
19runner = CliRunner() 1abcdefgh
22def test_enum_choice() -> None: 1abcdefgh
23 # This test is only for coverage of the new custom TyperChoice class
24 result = runner.invoke(app, ["--name", "morty"], catch_exceptions=False) 1abcdefgh
25 assert result.exit_code == 0 1abcdefgh
26 assert "Hello Morty!" in result.output 1abcdefgh
28 result = runner.invoke(app, ["--name", "Rick"]) 1abcdefgh
29 assert result.exit_code == 0 1abcdefgh
30 assert "Hello Rick!" in result.output 1abcdefgh
32 result = runner.invoke(app, ["--name", "RICK"]) 1abcdefgh
33 assert result.exit_code == 0 1abcdefgh
34 assert "Hello Rick!" in result.output 1abcdefgh