@@ -1653,7 +1653,48 @@ def cli(one, two):
16531653 runner .invoke (cli , [])
16541654
16551655
1656- def test_custom_type_flag_value_default (runner ):
1656+ class EngineType (enum .Enum ):
1657+ OSS = enum .auto ()
1658+ PRO = enum .auto ()
1659+ MAX = enum .auto ()
1660+
1661+
1662+ @pytest .mark .parametrize (
1663+ ("opt_params" , "args" , "expected" ),
1664+ [
1665+ ({"flag_value" : None }, [], "None" ),
1666+ ({"flag_value" : None }, ["--pro" ], "None" ),
1667+ ({"flag_value" : EngineType .MAX }, [], "None" ),
1668+ ({"flag_value" : EngineType .MAX }, ["--pro" ], "<EngineType.MAX: 3>" ),
1669+ ({"default" : EngineType .OSS }, [], "<EngineType.OSS: 1>" ),
1670+ (
1671+ {"default" : EngineType .OSS },
1672+ ["--pro" ],
1673+ "Error: Option '--pro' requires an argument.\n " ,
1674+ ),
1675+ ({"is_flag" : True , "default" : EngineType .OSS }, [], "<EngineType.OSS: 1>" ),
1676+ (
1677+ {"is_flag" : True , "default" : EngineType .OSS },
1678+ ["--pro" ],
1679+ "<EngineType.OSS: 1>" ,
1680+ ),
1681+ ],
1682+ )
1683+ def test_custom_type_enum_flag_value (runner , opt_params , args , expected ):
1684+ """A reproduction of
1685+ https://github.com/pallets/click/issues/3024#issuecomment-3146480714
1686+ """
1687+
1688+ @click .command ()
1689+ @click .option ("--pro" , type = EngineType , ** opt_params )
1690+ def scan (pro ):
1691+ click .echo (repr (pro ), nl = False )
1692+
1693+ result = runner .invoke (scan , args )
1694+ assert result .output == expected
1695+
1696+
1697+ def test_custom_type_frozenset_flag_value (runner ):
16571698 """A reproduction of https://github.com/pallets/click/issues/2610"""
16581699
16591700 @click .command ()
0 commit comments