Skip to content

Commit 93fc609

Browse files
committed
Use asyncio instead of anyio in tests
1 parent 977cb71 commit 93fc609

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

tests/test_kernel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ def test_simple_print():
6161
def test_async_cell_waiting_for_comm_reply():
6262
with new_kernel() as kc:
6363
msg_id = kc.execute(
64-
"""import anyio, comm
65-
reply = anyio.Future()
64+
"""import asyncio, comm
65+
reply = asyncio.get_running_loop().create_future()
6666
widget = comm.create_comm(target_name='comm-reply-test')
67-
widget.on_msg(lambda msg: setattr(reply, 'return_value', msg['content']['data']['value']))
68-
with anyio.fail_after(5):
69-
await reply.wait()
70-
result = reply.return_value
67+
widget.on_msg(lambda msg: reply.set_result(msg['content']['data']['value']))
68+
result = await asyncio.wait_for(reply, 5)
7169
assert result == 42
7270
"""
7371
)
7472
while True:
7573
msg = kc.get_iopub_msg(timeout=10)
74+
if msg["msg_type"] == "error" and msg["parent_header"].get("msg_id") == msg_id:
75+
raise AssertionError("\n".join(msg["content"]["traceback"]))
7676
if msg["msg_type"] == "comm_open" and msg["parent_header"].get("msg_id") == msg_id:
7777
comm_id = msg["content"]["comm_id"]
7878
break

tests/test_subshells.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,27 @@ def test_comm_reply_follows_requesting_subshell():
144144

145145
msg = execute_request(
146146
kc,
147-
"""import anyio, threading
148-
reply = anyio.Future()
147+
"""import asyncio, threading
148+
reply = asyncio.get_running_loop().create_future()
149149
request_thread = threading.get_ident()
150150
def on_reply(message):
151151
global callback_thread
152152
callback_thread = threading.get_ident()
153-
reply.return_value = message['content']['data']['content']['value']
153+
reply.set_result(message['content']['data']['content']['value'])
154154
widget.on_msg(on_reply)
155155
widget.send({'method': 'custom', 'content': {'id': 'request-1', 'operation': 'get'}})
156-
with anyio.fail_after(2):
157-
await reply.wait()
158-
assert reply.return_value == 42
156+
assert await asyncio.wait_for(reply, 2) == 42
159157
assert callback_thread == request_thread
160158
""",
161159
None,
162160
)
163161
while True:
164162
outgoing = kc.get_iopub_msg(timeout=10)
163+
if (
164+
outgoing["msg_type"] == "error"
165+
and outgoing["parent_header"].get("msg_id") == msg["header"]["msg_id"]
166+
):
167+
raise AssertionError("\n".join(outgoing["content"]["traceback"]))
165168
if (
166169
outgoing["msg_type"] == "comm_msg"
167170
and outgoing["parent_header"].get("msg_id") == msg["header"]["msg_id"]

0 commit comments

Comments
 (0)