-
-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version of the test as tutorial003 for parameter type enum
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
17 changes: 17 additions & 0 deletions
17
tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |