Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Jun 7, 2023
1 parent 39cf98f commit d6329be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/py/reactpy/reactpy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
variables or, for those which allow it, a programmatic interface.
"""

from __future__ import annotations

from pathlib import Path
from tempfile import TemporaryDirectory

Expand All @@ -12,9 +14,11 @@
FALSE_VALUES = {"false", "0"}


def boolean(value: str | bool) -> bool:
def boolean(value: str | bool | int) -> bool:
if isinstance(value, bool):
return value
elif isinstance(value, int):
return bool(value)
elif not isinstance(value, str):
raise TypeError(f"Expected str or bool, got {type(value).__name__}")

Expand Down
7 changes: 7 additions & 0 deletions src/py/reactpy/tests/test__option.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ def test_option_parent_child_must_be_mutable():
Option("A_FAKE_OPTION", parent=mut_parent_opt, mutable=False)
with pytest.raises(TypeError, match="must be mutable"):
Option("A_FAKE_OPTION", parent=immu_parent_opt, mutable=None)


def test_no_default_or_parent():
with pytest.raises(
TypeError, match="must specify either a default value or a parent"
):
Option("A_FAKE_OPTION")
24 changes: 24 additions & 0 deletions src/py/reactpy/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ def test_reactpy_debug_mode_toggle():
# just check that nothing breaks
config.REACTPY_DEBUG_MODE.current = True
config.REACTPY_DEBUG_MODE.current = False


def test_boolean():
assert config.boolean(True) is True
assert config.boolean(False) is False
assert config.boolean(1) is True
assert config.boolean(0) is False
assert config.boolean("true") is True
assert config.boolean("false") is False
assert config.boolean("True") is True
assert config.boolean("False") is False
assert config.boolean("TRUE") is True
assert config.boolean("FALSE") is False
assert config.boolean("1") is True
assert config.boolean("0") is False

with pytest.raises(ValueError):
config.boolean("2")

with pytest.raises(ValueError):
config.boolean("")

with pytest.raises(TypeError):
config.boolean(None)

0 comments on commit d6329be

Please sign in to comment.