-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathtest_config.py
53 lines (40 loc) · 1.42 KB
/
test_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pytest
from reactpy import config
from reactpy._option import Option
@pytest.fixture(autouse=True)
def reset_options():
options = [value for value in config.__dict__.values() if isinstance(value, Option)]
should_unset = object()
original_values = []
for opt in options:
original_values.append(opt.current if opt.is_set() else should_unset)
yield
for opt, val in zip(options, original_values):
if val is should_unset:
if opt.is_set():
opt.unset()
else:
opt.current = val
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)