File: test_types.py

package info (click to toggle)
typer 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: python: 16,702; javascript: 280; sh: 28; makefile: 27
file content (34 lines) | stat: -rw-r--r-- 841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from enum import Enum

import typer
from typer.testing import CliRunner

app = typer.Typer(context_settings={"token_normalize_func": str.lower})


class User(str, Enum):
    rick = "Rick"
    morty = "Morty"


@app.command()
def hello(name: User = User.rick) -> None:
    print(f"Hello {name.value}!")


runner = CliRunner()


def test_enum_choice() -> None:
    # This test is only for coverage of the new custom TyperChoice class
    result = runner.invoke(app, ["--name", "morty"], catch_exceptions=False)
    assert result.exit_code == 0
    assert "Hello Morty!" in result.output

    result = runner.invoke(app, ["--name", "Rick"])
    assert result.exit_code == 0
    assert "Hello Rick!" in result.output

    result = runner.invoke(app, ["--name", "RICK"])
    assert result.exit_code == 0
    assert "Hello Rick!" in result.output