Skip to content

Commit 1ea757c

Browse files
committed
get suite to run (with failures)
1 parent 7f10258 commit 1ea757c

File tree

7 files changed

+5
-290
lines changed

7 files changed

+5
-290
lines changed

tests/test_client.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import idom
66
from idom.testing import ServerFixture
7-
from tests.tooling.browser import send_keys
87

98

109
JS_DIR = Path(__file__).parent / "js"

tests/test_core/test_dispatcher.py

+1-88
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66

77
import idom
88
from idom.core.layout import Layout, LayoutEvent, LayoutUpdate
9-
from idom.core.serve import (
10-
VdomJsonPatch,
11-
_create_shared_view_dispatcher,
12-
create_shared_view_dispatcher,
13-
ensure_shared_view_dispatcher_future,
14-
serve_json_patch,
15-
)
9+
from idom.core.serve import VdomJsonPatch, serve_json_patch
1610
from idom.testing import StaticEventHandler
1711

1812

@@ -102,87 +96,6 @@ async def test_dispatch():
10296
assert_changes_produce_expected_model(changes, expected_model)
10397

10498

105-
async def test_create_shared_state_dispatcher():
106-
events, model = make_events_and_expected_model()
107-
changes_1, send_1, recv_1 = make_send_recv_callbacks(events)
108-
changes_2, send_2, recv_2 = make_send_recv_callbacks(events)
109-
110-
async with create_shared_view_dispatcher(Layout(Counter())) as dispatcher:
111-
dispatcher(send_1, recv_1)
112-
dispatcher(send_2, recv_2)
113-
114-
assert_changes_produce_expected_model(changes_1, model)
115-
assert_changes_produce_expected_model(changes_2, model)
116-
117-
118-
async def test_ensure_shared_view_dispatcher_future():
119-
events, model = make_events_and_expected_model()
120-
changes_1, send_1, recv_1 = make_send_recv_callbacks(events)
121-
changes_2, send_2, recv_2 = make_send_recv_callbacks(events)
122-
123-
dispatch_future, dispatch = ensure_shared_view_dispatcher_future(Layout(Counter()))
124-
125-
await asyncio.gather(
126-
dispatch(send_1, recv_1),
127-
dispatch(send_2, recv_2),
128-
return_exceptions=True,
129-
)
130-
131-
# the dispatch future should run forever, until cancelled
132-
with pytest.raises(asyncio.TimeoutError):
133-
await asyncio.wait_for(dispatch_future, timeout=1)
134-
135-
dispatch_future.cancel()
136-
await asyncio.gather(dispatch_future, return_exceptions=True)
137-
138-
assert_changes_produce_expected_model(changes_1, model)
139-
assert_changes_produce_expected_model(changes_2, model)
140-
141-
142-
async def test_private_create_shared_view_dispatcher_cleans_up_patch_queues():
143-
"""Report an issue if this test breaks
144-
145-
Some internals of idom.core.dispatcher may need to be changed in order to make some
146-
internal state easier to introspect.
147-
148-
Ideally we would just check if patch queues are getting cleaned up more directly,
149-
but without having access to that, we use some side effects to try and infer whether
150-
it happens.
151-
"""
152-
153-
@idom.component
154-
def SomeComponent():
155-
return idom.html.div()
156-
157-
async def send(patch):
158-
raise idom.Stop()
159-
160-
async def recv():
161-
return LayoutEvent("something", [])
162-
163-
with idom.Layout(SomeComponent()) as layout:
164-
dispatch_shared_view, push_patch = await _create_shared_view_dispatcher(layout)
165-
166-
# Dispatch a view that should exit. After exiting its patch queue should be
167-
# cleaned up and removed. Since we only dispatched one view there should be
168-
# no patch queues.
169-
await dispatch_shared_view(send, recv) # this should stop immediately
170-
171-
# We create a patch and check its ref count. We will check this after attempting
172-
# to push out the change.
173-
patch = VdomJsonPatch("anything", [])
174-
patch_ref_count = sys.getrefcount(patch)
175-
176-
# We push out this change.
177-
push_patch(patch)
178-
179-
# Because there should be no patch queues, we expect that the ref count remains
180-
# the same. If the ref count had increased, then we would know that the patch
181-
# queue has not been cleaned up and that the patch we just pushed was added to
182-
# it.
183-
assert not sys.getrefcount(patch) > patch_ref_count
184-
185-
18699
async def test_dispatcher_handles_more_than_one_event_at_a_time():
187100
block_and_never_set = asyncio.Event()
188101
will_block = asyncio.Event()

tests/test_server/test_common/test_per_client_state.py renamed to tests/test_server/test_common.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
import pytest
22

33
import idom
4-
from idom.server import fastapi as idom_fastapi
5-
from idom.server import flask as idom_flask
6-
from idom.server import sanic as idom_sanic
7-
from idom.server import starlette as idom_starlette
8-
from idom.server import tornado as idom_tornado
4+
from idom.server.utils import all_implementations
95
from idom.testing import ServerFixture
106

117

128
@pytest.fixture(
13-
params=[
14-
# add new PerClientStateServer implementations here to
15-
# run a suite of tests which check basic functionality
16-
idom_fastapi.PerClientStateServer,
17-
idom_flask.PerClientStateServer,
18-
idom_sanic.PerClientStateServer,
19-
idom_starlette.PerClientStateServer,
20-
idom_tornado.PerClientStateServer,
21-
],
22-
ids=lambda cls: f"{cls.__module__}.{cls.__name__}",
9+
params=list(all_implementations()),
10+
ids=lambda imp: imp.__name__,
2311
)
2412
def server_mount_point(request):
2513
with ServerFixture(request.param) as mount_point:

tests/test_server/test_common/__init__.py

Whitespace-only changes.

tests/test_server/test_common/test_multiview.py

-46
This file was deleted.

tests/test_server/test_common/test_shared_state_client.py

-125
This file was deleted.

tests/test_server/test_utils.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,7 @@
22

33
import pytest
44

5-
from idom.server.utils import find_available_port, poll, wait_on_event
6-
7-
8-
def test_poll():
9-
with pytest.raises(TimeoutError, match="Did not do something within 0.1 seconds"):
10-
poll("do something", 0.01, 0.1, lambda: False)
11-
poll("do something", 0.01, None, [True, False, False].pop)
12-
13-
14-
def test_wait_on_event():
15-
event = Event()
16-
with pytest.raises(TimeoutError, match="Did not do something within 0.1 seconds"):
17-
wait_on_event("do something", event, 0.1)
18-
event.set()
19-
wait_on_event("do something", event, None)
5+
from idom.server.utils import find_available_port
206

217

228
def test_find_available_port():

0 commit comments

Comments
 (0)