|
3 | 3 | # Copyright (c) Jupyter Development Team.
|
4 | 4 | # Distributed under the terms of the Modified BSD License.
|
5 | 5 |
|
6 |
| -import unittest |
7 |
| - |
8 | 6 | from qtconsole.inprocess import QtInProcessKernelManager
|
9 |
| - |
10 |
| - |
11 |
| -class InProcessTests(unittest.TestCase): |
12 |
| - |
13 |
| - def setUp(self): |
14 |
| - """Open an in-process kernel.""" |
15 |
| - self.kernel_manager = QtInProcessKernelManager() |
16 |
| - self.kernel_manager.start_kernel() |
17 |
| - self.kernel_client = self.kernel_manager.client() |
18 |
| - |
19 |
| - def tearDown(self): |
20 |
| - """Shutdown the in-process kernel. """ |
21 |
| - self.kernel_client.stop_channels() |
22 |
| - self.kernel_manager.shutdown_kernel() |
23 |
| - |
24 |
| - def test_execute(self): |
25 |
| - """Test execution of shell commands.""" |
26 |
| - # check that closed works as expected |
27 |
| - assert not self.kernel_client.iopub_channel.closed() |
28 |
| - |
29 |
| - # check that running code works |
30 |
| - self.kernel_client.execute('a=1') |
31 |
| - assert self.kernel_manager.kernel.shell.user_ns.get('a') == 1 |
| 7 | +from inspect import iscoroutinefunction |
| 8 | +import pytest |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.asyncio |
| 12 | +async def test_execute(): |
| 13 | + kernel_manager = QtInProcessKernelManager() |
| 14 | + if iscoroutinefunction(kernel_manager.start_kernel): |
| 15 | + await kernel_manager.start_kernel() |
| 16 | + else: |
| 17 | + kernel_manager.start_kernel() |
| 18 | + kernel_client = kernel_manager.client() |
| 19 | + |
| 20 | + """Test execution of shell commands.""" |
| 21 | + # check that closed works as expected |
| 22 | + assert not kernel_client.iopub_channel.closed() |
| 23 | + |
| 24 | + # check that running code works |
| 25 | + kernel_client.execute("a=1") |
| 26 | + assert kernel_manager.kernel is not None, "kernel has likely not started" |
| 27 | + assert kernel_manager.kernel.shell.user_ns.get("a") == 1 |
| 28 | + |
| 29 | + kernel_client.stop_channels() |
| 30 | + kernel_manager.shutdown_kernel() |
0 commit comments