Skip to content

Commit d6329be

Browse files
committed
add more tests
1 parent 39cf98f commit d6329be

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

Diff for: src/py/reactpy/reactpy/config.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
variables or, for those which allow it, a programmatic interface.
44
"""
55

6+
from __future__ import annotations
7+
68
from pathlib import Path
79
from tempfile import TemporaryDirectory
810

@@ -12,9 +14,11 @@
1214
FALSE_VALUES = {"false", "0"}
1315

1416

15-
def boolean(value: str | bool) -> bool:
17+
def boolean(value: str | bool | int) -> bool:
1618
if isinstance(value, bool):
1719
return value
20+
elif isinstance(value, int):
21+
return bool(value)
1822
elif not isinstance(value, str):
1923
raise TypeError(f"Expected str or bool, got {type(value).__name__}")
2024

Diff for: src/py/reactpy/tests/test__option.py

+7
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,10 @@ def test_option_parent_child_must_be_mutable():
128128
Option("A_FAKE_OPTION", parent=mut_parent_opt, mutable=False)
129129
with pytest.raises(TypeError, match="must be mutable"):
130130
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")

Diff for: src/py/reactpy/tests/test_config.py

+24
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,27 @@ def test_reactpy_debug_mode_toggle():
2727
# just check that nothing breaks
2828
config.REACTPY_DEBUG_MODE.current = True
2929
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)

0 commit comments

Comments
 (0)