Skip to content

Commit 5c0b4a6

Browse files
committed
✅ Add extra test for coverage
1 parent 7da4979 commit 5c0b4a6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_types.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from enum import Enum
2+
3+
import typer
4+
from typer.testing import CliRunner
5+
6+
app = typer.Typer(context_settings={"token_normalize_func": str.lower})
7+
8+
9+
class User(str, Enum):
10+
rick = "Rick"
11+
morty = "Morty"
12+
13+
14+
@app.command()
15+
def hello(name: User = User.rick) -> None:
16+
print(f"Hello {name.value}!")
17+
18+
19+
runner = CliRunner()
20+
21+
22+
def test_enum_choice() -> None:
23+
# This test is only for coverage of the new custom TyperChoice class
24+
result = runner.invoke(app, ["--name", "morty"], catch_exceptions=False)
25+
# assert result.exit_code == 0
26+
assert "Hello Morty!" in result.output
27+
28+
result = runner.invoke(app, ["--name", "Rick"])
29+
assert result.exit_code == 0
30+
assert "Hello Rick!" in result.output
31+
32+
result = runner.invoke(app, ["--name", "RICK"])
33+
assert result.exit_code == 0
34+
assert "Hello Rick!" in result.output

0 commit comments

Comments
 (0)