Skip to content

Commit acec02b

Browse files
committed
Delete always skipped tests that used removed attributes
And try to fix trio tests
1 parent 042fa04 commit acec02b

File tree

5 files changed

+30
-84
lines changed

5 files changed

+30
-84
lines changed

ipykernel/kernelapp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,23 @@ def initialize(self, argv=None):
730730
sys.stdout.flush()
731731
sys.stderr.flush()
732732

733-
def start(self) -> None:
734-
"""Start the application."""
733+
async def _start(self) -> None:
734+
"""
735+
Async version of start, when the loop is not controlled by IPykernel
736+
737+
For example to be used in test suite with @pytest.mark.trio
738+
"""
735739
if self.subapp is not None:
736740
self.subapp.start()
737-
return
741+
return None
738742
if self.poller is not None:
739743
self.poller.start()
744+
return await self.main()
745+
746+
def start(self) -> None:
747+
"""Start the application."""
740748
backend = "trio" if self.trio_loop else "asyncio"
741-
run(self.main, backend=backend)
749+
run(self._start, backend=backend)
742750
return
743751

744752
async def _wait_to_enter_eventloop(self):

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ docs = [
5454
"trio"
5555
]
5656
test = [
57-
"pytest>=7.0,<9",
58-
"pytest-cov",
5957
"flaky",
6058
"ipyparallel",
6159
"pre-commit",
60+
"pytest-asyncio>=0.23.5",
61+
"pytest-cov",
6262
"pytest-timeout",
63+
"anyio[trio]",
64+
"pytest>=7.0,<9",
6365
"trio",
64-
"pytest-asyncio>=0.23.5",
6566
]
6667
cov = [
6768
"coverage[toml]",

tests/test_ipkernel_direct.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test IPythonKernel directly"""
22

3-
import asyncio
43
import os
54

65
import pytest
@@ -152,49 +151,12 @@ async def test_direct_clear(ipkernel):
152151
ipkernel.do_clear()
153152

154153

155-
@pytest.mark.skip("ipykernel._cancel_on_sigint doesn't exist anymore")
156-
async def test_cancel_on_sigint(ipkernel: IPythonKernel) -> None:
157-
future: asyncio.Future = asyncio.Future()
158-
# with ipkernel._cancel_on_sigint(future):
159-
# pass
160-
future.set_result(None)
161-
162-
163154
async def test_dispatch_debugpy(ipkernel: IPythonKernel) -> None:
164155
msg = ipkernel.session.msg("debug_request", {})
165156
msg_list = ipkernel.session.serialize(msg)
166157
await ipkernel.receive_debugpy_message(msg_list)
167158

168159

169-
@pytest.mark.skip("Queues don't exist anymore")
170-
async def test_start(ipkernel: IPythonKernel) -> None:
171-
shell_future: asyncio.Future = asyncio.Future()
172-
173-
async def fake_dispatch_queue():
174-
shell_future.set_result(None)
175-
176-
ipkernel.dispatch_queue = fake_dispatch_queue # type:ignore
177-
ipkernel.start()
178-
ipkernel.debugpy_stream = None
179-
ipkernel.start()
180-
await ipkernel.process_one(False)
181-
await shell_future
182-
183-
184-
@pytest.mark.skip("Queues don't exist anymore")
185-
async def test_start_no_debugpy(ipkernel: IPythonKernel) -> None:
186-
shell_future: asyncio.Future = asyncio.Future()
187-
188-
async def fake_dispatch_queue():
189-
shell_future.set_result(None)
190-
191-
ipkernel.dispatch_queue = fake_dispatch_queue # type:ignore
192-
ipkernel.debugpy_stream = None
193-
ipkernel.start()
194-
195-
await shell_future
196-
197-
198160
def test_create_comm():
199161
assert isinstance(_create_comm(), BaseComm)
200162

tests/test_kernel_direct.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
55

6-
import asyncio
76
import os
8-
import warnings
97

108
import pytest
119

@@ -108,19 +106,6 @@ async def test_direct_debug_request(kernel):
108106
assert reply["header"]["msg_type"] == "debug_reply"
109107

110108

111-
@pytest.mark.skip("Shell streams don't exist anymore")
112-
async def test_deprecated_features(kernel):
113-
with warnings.catch_warnings():
114-
warnings.simplefilter("ignore", DeprecationWarning)
115-
header = kernel._parent_header
116-
assert isinstance(header, dict)
117-
shell_streams = kernel.shell_streams
118-
assert len(shell_streams) == 1
119-
assert shell_streams[0] == kernel.shell_stream
120-
warnings.simplefilter("ignore", RuntimeWarning)
121-
kernel.shell_streams = [kernel.shell_stream, kernel.shell_stream]
122-
123-
124109
async def test_process_control(kernel):
125110
from jupyter_client.session import DELIM
126111

@@ -142,12 +127,6 @@ async def test_dispatch_shell(kernel):
142127
await kernel.process_shell_message(msg)
143128

144129

145-
@pytest.mark.skip("kernelbase.do_one_iteration doesn't exist anymore")
146-
async def test_do_one_iteration(kernel):
147-
kernel.msg_queue = asyncio.Queue()
148-
await kernel.do_one_iteration()
149-
150-
151130
async def test_publish_debug_event(kernel):
152131
kernel._publish_debug_event({})
153132

@@ -160,7 +139,7 @@ async def test_send_interrupt_children(kernel):
160139
kernel._send_interrupt_children()
161140

162141

163-
# TODO: this causes deadlock
164-
# async def test_direct_usage_request(kernel):
165-
# reply = await kernel.test_control_message("usage_request", {})
166-
# assert reply['header']['msg_type'] == 'usage_reply'
142+
@pytest.mark.skip(reason="this causes deadlock")
143+
async def test_direct_usage_request(kernel):
144+
reply = await kernel.test_control_message("usage_request", {})
145+
assert reply["header"]["msg_type"] == "usage_reply"

tests/test_kernelapp.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
from .conftest import MockKernel
1313
from .utils import TemporaryWorkingDirectory
1414

15-
try:
16-
import trio
17-
except ImportError:
18-
trio = None
19-
2015

2116
@pytest.mark.skipif(os.name == "nt", reason="requires ipc")
2217
def test_init_ipc_socket():
@@ -117,21 +112,22 @@ def test_merge_connection_file():
117112
os.remove(cf)
118113

119114

120-
# FIXME: @pytest.mark.skipif(trio is None, reason="requires trio")
121-
@pytest.mark.skip()
122-
def test_trio_loop():
115+
@pytest.mark.skip("Something wrong with CI")
116+
@pytest.mark.parametrize("anyio_backend", ["trio"])
117+
async def test_trio_loop(anyio_backend):
118+
import trio
119+
123120
app = IPKernelApp(trio_loop=True)
124121

125-
def trigger_stop():
126-
time.sleep(1)
122+
async def trigger_stop():
123+
await trio.sleep(1)
127124
app.stop()
128125

129-
thread = threading.Thread(target=trigger_stop)
130-
thread.start()
131-
132126
app.kernel = MockKernel()
133127
app.init_sockets()
134-
app.start()
128+
async with trio.open_nursery() as nursery:
129+
nursery.start_soon(app._start)
130+
nursery.start_soon(trigger_stop)
135131
app.cleanup_connection_file()
136132
app.kernel.destroy()
137133
app.close()

0 commit comments

Comments
 (0)