test_kernelmanager.py
54 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
Brian E. Granger
|
r9151 | """Tests for the notebook kernel and session manager""" | ||
Brian Granger
|
r9126 | |||
Brian E. Granger
|
r9132 | from subprocess import PIPE | ||
Brian E. Granger
|
r9131 | import time | ||
Brian Granger
|
r9126 | from unittest import TestCase | ||
MinRK
|
r9156 | from IPython.testing import decorators as dec | ||
Brian Granger
|
r9126 | from IPython.config.loader import Config | ||
MinRK
|
r10284 | from IPython.kernel import KernelManager | ||
Brian Granger
|
r9126 | |||
class TestKernelManager(TestCase): | ||||
def _get_tcp_km(self): | ||||
Brian Granger
|
r10282 | c = Config() | ||
km = KernelManager(config=c) | ||||
return km | ||||
Brian Granger
|
r9126 | |||
def _get_ipc_km(self): | ||||
c = Config() | ||||
c.KernelManager.transport = 'ipc' | ||||
c.KernelManager.ip = 'test' | ||||
km = KernelManager(config=c) | ||||
return km | ||||
def _run_lifecycle(self, km): | ||||
Brian E. Granger
|
r9132 | km.start_kernel(stdout=PIPE, stderr=PIPE) | ||
Brian E. Granger
|
r10275 | self.assertTrue(km.is_alive()) | ||
MinRK
|
r12416 | km.restart_kernel(now=True) | ||
Brian E. Granger
|
r10275 | self.assertTrue(km.is_alive()) | ||
Brian Granger
|
r9126 | km.interrupt_kernel() | ||
self.assertTrue(isinstance(km, KernelManager)) | ||||
MinRK
|
r12416 | km.shutdown_kernel(now=True) | ||
Brian Granger
|
r9126 | |||
Brian E. Granger
|
r9131 | def test_tcp_lifecycle(self): | ||
Brian Granger
|
r9126 | km = self._get_tcp_km() | ||
self._run_lifecycle(km) | ||||
MinRK
|
r9156 | @dec.skip_win32 | ||
MinRK
|
r9376 | def test_ipc_lifecycle(self): | ||
Brian Granger
|
r9126 | km = self._get_ipc_km() | ||
self._run_lifecycle(km) | ||||
MinRK
|
r11840 | |||
def test_get_connect_info(self): | ||||
km = self._get_tcp_km() | ||||
cinfo = km.get_connection_info() | ||||
keys = sorted(cinfo.keys()) | ||||
expected = sorted([ | ||||
'ip', 'transport', | ||||
'hb_port', 'shell_port', 'stdin_port', 'iopub_port', 'control_port', | ||||
'key', 'signature_scheme', | ||||
]) | ||||
self.assertEqual(keys, expected) | ||||
Brian E. Granger
|
r9131 | |||