-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for kernel action events
- Loading branch information
Showing
3 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from jupyter_client.manager import AsyncKernelManager | ||
|
||
from jupyter_server.services.kernels.kernelmanager import ServerKernelManager | ||
|
||
pytest_plugins = ["jupyter_events.pytest_plugin"] | ||
|
||
|
||
@pytest.mark.parametrize("action", ["start", "restart", "interrupt", "shutdown"]) | ||
async def test_kernel_action_event(monkeypatch, action, jp_read_emitted_events, jp_event_handler): | ||
manager = ServerKernelManager() | ||
manager.event_logger.register_handler(jp_event_handler) | ||
|
||
async def mock_method(self, *args, **kwargs): | ||
self.kernel_id = "x-x-x-x-x" | ||
... | ||
|
||
monkeypatch.setattr(AsyncKernelManager, f"{action}_kernel", mock_method) | ||
|
||
await getattr(manager, f"{action}_kernel")() | ||
|
||
output = jp_read_emitted_events()[0] | ||
assert "action" in output and output["action"] == action | ||
assert "msg" in output | ||
assert "kernel_id" in output |