Skip to content

Commit

Permalink
Add version of the test as tutorial003 for parameter type enum
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Mar 6, 2024
1 parent 6e6ea7c commit db416e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs_src/parameter_types/enum/tutorial003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from enum import Enum

import typer


class Interval(Enum):
ONE_MINUTE = "1m"
ONE_MONTH = "1M"
OTHER = "o"


def main(
interval: Interval = typer.Option(Interval.OTHER, case_sensitive=True)
):
print(f"Found interval: {interval.value}")


if __name__ == "__main__":
typer.run(main)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
import typer
from typer.testing import CliRunner

from docs_src.parameter_types.enum import tutorial003 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


@pytest.mark.parametrize("interval", ["1M", "1m"])
def test_case(interval):
result = runner.invoke(app, ["--interval", interval])
assert result.exit_code == 0
assert f"Found interval: {interval}" in result.output

0 comments on commit db416e1

Please sign in to comment.