File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments