Skip to content

Commit 6fc8203

Browse files
committed
fix tests
1 parent 273db36 commit 6fc8203

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/idom/_option.py

+4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def unset(self) -> None:
107107
"""Remove the current value, the default will be used until it is set again."""
108108
if not self._mutable:
109109
raise TypeError(f"{self} cannot be modified after initial load")
110+
old = self.current
110111
delattr(self, "_current")
112+
if self.current != old:
113+
for sub_func in self._subscribers:
114+
sub_func(self.current)
111115

112116
def __repr__(self) -> str:
113117
return f"Option({self._name}={self.current!r})"

tests/test__option.py

+3
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ def test_option_subscribe():
9696
opt.current = "new-1"
9797
opt.current = "new-2"
9898
assert calls == ["default", "new-1", "new-2"]
99+
100+
opt.unset()
101+
assert calls == ["default", "new-1", "new-2", "default"]

tests/test_config.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
from idom.config import IDOM_DEBUG_MODE
1+
import pytest
2+
3+
from idom import config
4+
from idom._option import Option
5+
6+
7+
@pytest.fixture(autouse=True)
8+
def reset_options():
9+
options = [value for value in config.__dict__.values() if isinstance(value, Option)]
10+
11+
should_unset = object()
12+
original_values = []
13+
for opt in options:
14+
original_values.append(opt.current if opt.is_set() else should_unset)
15+
16+
yield
17+
18+
for opt, val in zip(options, original_values):
19+
if val is should_unset:
20+
if opt.is_set():
21+
opt.unset()
22+
else:
23+
opt.current = val
224

325

426
def test_idom_debug_mode_toggle():
527
# just check that nothing breaks
6-
IDOM_DEBUG_MODE.current = True
7-
IDOM_DEBUG_MODE.current = False
28+
config.IDOM_DEBUG_MODE.current = True
29+
config.IDOM_DEBUG_MODE.current = False

0 commit comments

Comments
 (0)