Skip to content
Myr

test_types.py

This file

Path

tests/test_types.py

34 lines 路 841 bytes 路 Python

Last changed by

猬嗭笍 Add compatibility with Click 8.2 (#1222)Sebasti谩n Ram铆rezbefore adoption74e0923

History of this file

Take it

1from enum import Enum23import typer4from typer.testing import CliRunner56app = typer.Typer(context_settings={"token_normalize_func": str.lower})789class User(str, Enum):10    rick = "Rick"11    morty = "Morty"121314@app.command()15def hello(name: User = User.rick) -> None:16    print(f"Hello {name.value}!")171819runner = CliRunner()202122def test_enum_choice() -> None:23    # This test is only for coverage of the new custom TyperChoice class24    result = runner.invoke(app, ["--name", "morty"], catch_exceptions=False)25    assert result.exit_code == 026    assert "Hello Morty!" in result.output2728    result = runner.invoke(app, ["--name", "Rick"])29    assert result.exit_code == 030    assert "Hello Rick!" in result.output3132    result = runner.invoke(app, ["--name", "RICK"])33    assert result.exit_code == 034    assert "Hello Rick!" in result.output