|
| 1 | +"""Test IPythonKernel directly""" |
| 2 | + |
| 3 | +import asyncio |
| 4 | +import os |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from ipykernel.ipkernel import IPythonKernel |
| 9 | + |
| 10 | +if os.name == "nt": |
| 11 | + pytest.skip("skipping tests on windows", allow_module_level=True) |
| 12 | + |
| 13 | + |
| 14 | +class user_mod: |
| 15 | + __dict__ = {} |
| 16 | + |
| 17 | + |
| 18 | +async def test_properities(ipkernel: IPythonKernel): |
| 19 | + ipkernel.user_module = user_mod() |
| 20 | + ipkernel.user_ns = {} |
| 21 | + |
| 22 | + |
| 23 | +async def test_direct_kernel_info_request(ipkernel): |
| 24 | + reply = await ipkernel.test_shell_message("kernel_info_request", {}) |
| 25 | + assert reply["header"]["msg_type"] == "kernel_info_reply" |
| 26 | + |
| 27 | + |
| 28 | +async def test_direct_execute_request(ipkernel): |
| 29 | + reply = await ipkernel.test_shell_message("execute_request", dict(code="hello", silent=False)) |
| 30 | + assert reply["header"]["msg_type"] == "execute_reply" |
| 31 | + |
| 32 | + |
| 33 | +async def test_direct_execute_request_aborting(ipkernel): |
| 34 | + ipkernel._aborting = True |
| 35 | + reply = await ipkernel.test_shell_message("execute_request", dict(code="hello", silent=False)) |
| 36 | + assert reply["header"]["msg_type"] == "execute_reply" |
| 37 | + assert reply["content"]["status"] == "aborted" |
| 38 | + |
| 39 | + |
| 40 | +async def test_complete_request(ipkernel): |
| 41 | + reply = await ipkernel.test_shell_message("complete_request", dict(code="hello", cursor_pos=0)) |
| 42 | + assert reply["header"]["msg_type"] == "complete_reply" |
| 43 | + |
| 44 | + |
| 45 | +async def test_inspect_request(ipkernel): |
| 46 | + reply = await ipkernel.test_shell_message("inspect_request", dict(code="hello", cursor_pos=0)) |
| 47 | + assert reply["header"]["msg_type"] == "inspect_reply" |
| 48 | + |
| 49 | + |
| 50 | +async def test_history_request(ipkernel): |
| 51 | + reply = await ipkernel.test_shell_message( |
| 52 | + "history_request", dict(hist_access_type="", output="", raw="") |
| 53 | + ) |
| 54 | + assert reply["header"]["msg_type"] == "history_reply" |
| 55 | + |
| 56 | + |
| 57 | +async def test_comm_info_request(ipkernel): |
| 58 | + reply = await ipkernel.test_shell_message("comm_info_request") |
| 59 | + assert reply["header"]["msg_type"] == "comm_info_reply" |
| 60 | + |
| 61 | + |
| 62 | +async def test_direct_interrupt_request(ipkernel): |
| 63 | + reply = await ipkernel.test_shell_message("interrupt_request", {}) |
| 64 | + assert reply["header"]["msg_type"] == "interrupt_reply" |
| 65 | + |
| 66 | + |
| 67 | +# TODO: this causes deadlock |
| 68 | +# async def test_direct_shutdown_request(ipkernel): |
| 69 | +# reply = await ipkernel.test_shell_message("shutdown_request", dict(restart=False)) |
| 70 | +# assert reply["header"]["msg_type"] == "shutdown_reply" |
| 71 | +# reply = await ipkernel.test_shell_message("shutdown_request", dict(restart=True)) |
| 72 | +# assert reply["header"]["msg_type"] == "shutdown_reply" |
| 73 | + |
| 74 | +# TODO: this causes deadlock |
| 75 | +# async def test_direct_usage_request(kernel): |
| 76 | +# reply = await kernel.test_control_message("usage_request", {}) |
| 77 | +# assert reply['header']['msg_type'] == 'usage_reply' |
| 78 | + |
| 79 | + |
| 80 | +async def test_is_complete_request(ipkernel): |
| 81 | + reply = await ipkernel.test_shell_message("is_complete_request", dict(code="hello")) |
| 82 | + assert reply["header"]["msg_type"] == "is_complete_reply" |
| 83 | + |
| 84 | + |
| 85 | +async def test_direct_debug_request(ipkernel): |
| 86 | + reply = await ipkernel.test_control_message("debug_request", {}) |
| 87 | + assert reply["header"]["msg_type"] == "debug_reply" |
| 88 | + |
| 89 | + |
| 90 | +async def test_direct_clear(ipkernel): |
| 91 | + ipkernel.do_clear() |
| 92 | + |
| 93 | + |
| 94 | +async def test_cancel_on_sigint(ipkernel: IPythonKernel): |
| 95 | + future = asyncio.Future() |
| 96 | + with ipkernel._cancel_on_sigint(future): |
| 97 | + pass |
| 98 | + future.set_result(None) |
0 commit comments