@@ -1007,6 +1007,31 @@ def test_type_from_flag_value():
1007
1007
assert param .type is click .INT
1008
1008
1009
1009
1010
+ @pytest .mark .parametrize (
1011
+ ("opts" , "pass_flag" , "expected" ),
1012
+ [
1013
+ pytest .param ({"type" : bool }, False , "False" ),
1014
+ pytest .param ({"type" : bool }, True , "True" ),
1015
+ pytest .param ({"type" : bool , "default" : True }, False , "True" ),
1016
+ pytest .param ({"type" : bool , "default" : True }, True , "False" ),
1017
+ pytest .param ({"type" : click .BOOL }, False , "False" ),
1018
+ pytest .param ({"type" : click .BOOL }, True , "True" ),
1019
+ pytest .param ({"type" : click .BOOL , "default" : True }, False , "True" ),
1020
+ pytest .param ({"type" : click .BOOL , "default" : True }, True , "False" ),
1021
+ pytest .param ({"type" : str }, False , "" ),
1022
+ pytest .param ({"type" : str }, True , "True" ),
1023
+ ],
1024
+ )
1025
+ def test_flag_value_is_correctly_set (runner , opts , pass_flag , expected ):
1026
+ @click .command ()
1027
+ @click .option ("--foo" , is_flag = True , ** opts )
1028
+ def cmd (foo ):
1029
+ click .echo (foo )
1030
+
1031
+ result = runner .invoke (cmd , ["--foo" ] if pass_flag else [])
1032
+ assert result .output == f"{ expected } \n "
1033
+
1034
+
1010
1035
@pytest .mark .parametrize (
1011
1036
("option" , "expected" ),
1012
1037
[
@@ -1040,6 +1065,20 @@ def test_invalid_flag_combinations(runner, kwargs, message):
1040
1065
assert message in str (e .value )
1041
1066
1042
1067
1068
+ def test_non_flag_with_non_negatable_default (runner ):
1069
+ class NonNegatable :
1070
+ def __bool__ (self ):
1071
+ raise ValueError ("Cannot negate this object" )
1072
+
1073
+ @click .command ()
1074
+ @click .option ("--foo" , default = NonNegatable ())
1075
+ def cmd (foo ):
1076
+ pass
1077
+
1078
+ result = runner .invoke (cmd )
1079
+ assert result .exit_code == 0
1080
+
1081
+
1043
1082
@pytest .mark .parametrize (
1044
1083
("choices" , "metavars" ),
1045
1084
[
0 commit comments