File tree 3 files changed +36
-1
lines changed
3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 3
3
variables or, for those which allow it, a programmatic interface.
4
4
"""
5
5
6
+ from __future__ import annotations
7
+
6
8
from pathlib import Path
7
9
from tempfile import TemporaryDirectory
8
10
12
14
FALSE_VALUES = {"false" , "0" }
13
15
14
16
15
- def boolean (value : str | bool ) -> bool :
17
+ def boolean (value : str | bool | int ) -> bool :
16
18
if isinstance (value , bool ):
17
19
return value
20
+ elif isinstance (value , int ):
21
+ return bool (value )
18
22
elif not isinstance (value , str ):
19
23
raise TypeError (f"Expected str or bool, got { type (value ).__name__ } " )
20
24
Original file line number Diff line number Diff line change @@ -128,3 +128,10 @@ def test_option_parent_child_must_be_mutable():
128
128
Option ("A_FAKE_OPTION" , parent = mut_parent_opt , mutable = False )
129
129
with pytest .raises (TypeError , match = "must be mutable" ):
130
130
Option ("A_FAKE_OPTION" , parent = immu_parent_opt , mutable = None )
131
+
132
+
133
+ def test_no_default_or_parent ():
134
+ with pytest .raises (
135
+ TypeError , match = "must specify either a default value or a parent"
136
+ ):
137
+ Option ("A_FAKE_OPTION" )
Original file line number Diff line number Diff line change @@ -27,3 +27,27 @@ def test_reactpy_debug_mode_toggle():
27
27
# just check that nothing breaks
28
28
config .REACTPY_DEBUG_MODE .current = True
29
29
config .REACTPY_DEBUG_MODE .current = False
30
+
31
+
32
+ def test_boolean ():
33
+ assert config .boolean (True ) is True
34
+ assert config .boolean (False ) is False
35
+ assert config .boolean (1 ) is True
36
+ assert config .boolean (0 ) is False
37
+ assert config .boolean ("true" ) is True
38
+ assert config .boolean ("false" ) is False
39
+ assert config .boolean ("True" ) is True
40
+ assert config .boolean ("False" ) is False
41
+ assert config .boolean ("TRUE" ) is True
42
+ assert config .boolean ("FALSE" ) is False
43
+ assert config .boolean ("1" ) is True
44
+ assert config .boolean ("0" ) is False
45
+
46
+ with pytest .raises (ValueError ):
47
+ config .boolean ("2" )
48
+
49
+ with pytest .raises (ValueError ):
50
+ config .boolean ("" )
51
+
52
+ with pytest .raises (TypeError ):
53
+ config .boolean (None )
You can’t perform that action at this time.
0 commit comments