Skip to content

Commit f460de0

Browse files
committed
start to fix tests
1 parent 6a18487 commit f460de0

11 files changed

Lines changed: 99 additions & 274 deletions

File tree

idom/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def set(self, value: _Current) -> None:
3232
def __eq__(self, other: Any) -> bool:
3333
return isinstance(other, Ref) and (other.current == self.current)
3434

35+
def __repr__(self) -> str:
36+
return f"{type(self).__name__}({self.current})"
37+
3538

3639
_ModelTransform = Callable[[Dict[str, Any]], Any]
3740

tests/conftest.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def display(
7171
mount: Callable[..., None],
7272
host: str,
7373
port: int,
74-
display_id: idom.Var[int],
75-
last_server_error: idom.Var[Exception],
74+
display_id: idom.Ref[int],
75+
last_server_error: idom.Ref[Exception],
7676
) -> Iterator[Callable[[Union[ElementConstructor, AbstractElement], str], None]]:
7777
"""A function for displaying an element using the current web driver."""
7878

@@ -81,7 +81,8 @@ def display(
8181
query: str = "",
8282
check_mount: bool = True,
8383
):
84-
d_id = display_id.set(display_id.value + 1)
84+
d_id = display_id.current
85+
display_id.current += 1
8586
display_attrs = {"id": f"display-{d_id}"}
8687
element_constructor = element if callable(element) else lambda: element
8788
mount(lambda: idom.html.div(display_attrs, element_constructor()))
@@ -93,7 +94,7 @@ def display(
9394
try:
9495
yield display
9596
finally:
96-
last_error = last_server_error.get()
97+
last_error = last_server_error.current
9798
if last_error is default_error:
9899
msg = f"The server {server} never ran or did not set the 'last_server_error' fixture."
99100
raise NotImplementedError(msg)
@@ -122,8 +123,8 @@ def driver_wait(driver: Chrome, driver_timeout: float) -> WebDriverWait:
122123

123124

124125
@pytest.fixture(scope="session")
125-
def display_id() -> idom.Var[int]:
126-
return idom.Var(0)
126+
def display_id() -> idom.Ref[int]:
127+
return idom.Ref(0)
127128

128129

129130
@pytest.fixture(scope="module")
@@ -190,7 +191,7 @@ def mount_and_server(
190191
fixturized_server_type: Type[AbstractRenderServer],
191192
host: str,
192193
port: int,
193-
last_server_error: idom.Var[Exception],
194+
last_server_error: idom.Ref[Exception],
194195
) -> Tuple[Callable[..., None], AbstractRenderServer]:
195196
"""An IDOM layout mount function and server as a tuple
196197
@@ -254,8 +255,8 @@ def port(host: str) -> int:
254255

255256
@pytest.fixture(scope="session")
256257
def last_server_error():
257-
"""A ``Var`` containing the last server error. This must be populated by ``server_type``"""
258-
return idom.Var(default_error)
258+
"""A ``Ref`` containing the last server error. This must be populated by ``server_type``"""
259+
return idom.Ref(default_error)
259260

260261

261262
@pytest.fixture(autouse=True)

tests/general_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def assert_unordered_equal(x, y):
2+
list_x = list(x)
3+
list_y = list(y)
4+
5+
assert len(x) == len(y) and all(
6+
# this is not very efficient unfortunately so don't compare anything large
7+
list_x.count(value) == list_y.count(value)
8+
for value in list_x
9+
)

tests/test_client/test_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ class FakeIpythonWithKernel:
8585

8686
def test_spinner_display_terminal(capsys):
8787
done = Event()
88-
display_count = idom.Var(0)
88+
display_count = idom.Ref(0)
8989

9090
class MySpinner(Spinner):
9191
def _display_terminal(self, frame, text):
92-
if display_count.value < 3 or frame in (
92+
if display_count.current < 3 or frame in (
9393
self.success_frame,
9494
self.failure_frame,
9595
None,
9696
):
9797
super()._display_terminal(frame, text)
98-
display_count.value += 1
98+
display_count.current += 1
9999
else:
100100
done.set()
101101

@@ -117,17 +117,17 @@ def _display_terminal(self, frame, text):
117117

118118
def test_spinner_display_notebook(mocker):
119119
done = Event()
120-
display_count = idom.Var(0)
120+
display_count = idom.Ref(0)
121121

122122
class MySpinner(Spinner):
123123
def _display_notebook(self, frame, text):
124-
if display_count.value < 3 or frame in (
124+
if display_count.current < 3 or frame in (
125125
self.success_frame,
126126
self.failure_frame,
127127
None,
128128
):
129129
super()._display_notebook(frame, text)
130-
display_count.value += 1
130+
display_count.current += 1
131131
else:
132132
done.set()
133133

tests/test_core/test_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def on_key_down(value):
104104

105105

106106
def test_simple_click_event(driver, display):
107-
clicked = idom.Var(False)
107+
clicked = idom.Ref(False)
108108

109109
@idom.element
110110
async def Button():

0 commit comments

Comments
 (0)