##// END OF EJS Templates
include stream creation in notebook KM tests
MinRK -
Show More
@@ -1,70 +1,76 b''
1 1 """Tests for the notebook kernel and session manager."""
2 2
3 3 from subprocess import PIPE
4 4 import time
5 5 from unittest import TestCase
6 6
7 7 from IPython.config.loader import Config
8 8 from IPython.frontend.html.notebook.kernelmanager import MultiKernelManager
9 9 from IPython.zmq.kernelmanager import KernelManager
10 10
11 11 class TestKernelManager(TestCase):
12 12
13 13 def _get_tcp_km(self):
14 14 return MultiKernelManager()
15 15
16 16 def _get_ipc_km(self):
17 17 c = Config()
18 18 c.KernelManager.transport = 'ipc'
19 19 c.KernelManager.ip = 'test'
20 20 km = MultiKernelManager(config=c)
21 21 return km
22 22
23 23 def _run_lifecycle(self, km):
24 24 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
25 25 self.assertTrue(kid in km)
26 26 self.assertTrue(kid in km.list_kernel_ids())
27 27 self.assertEqual(len(km),1)
28 28 km.restart_kernel(kid)
29 29 self.assertTrue(kid in km.list_kernel_ids())
30 30 # We need a delay here to give the restarting kernel a chance to
31 31 # restart. Otherwise, the interrupt will kill it, causing the test
32 32 # suite to hang. The reason it *hangs* is that the shutdown
33 33 # message for the restart sometimes hasn't been sent to the kernel.
34 34 # Because linger is oo on the shell channel, the context can't
35 35 # close until the message is sent to the kernel, which is not dead.
36 36 time.sleep(1.0)
37 37 km.interrupt_kernel(kid)
38 38 k = km.get_kernel(kid)
39 39 self.assertTrue(isinstance(k, KernelManager))
40 40 km.shutdown_kernel(kid)
41 41 self.assertTrue(not kid in km)
42 42
43 43 def _run_cinfo(self, km, transport, ip):
44 44 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
45 45 k = km.get_kernel(kid)
46 46 cinfo = km.get_connection_info(kid)
47 47 self.assertEqual(transport, cinfo['transport'])
48 48 self.assertEqual(ip, cinfo['ip'])
49 49 self.assertTrue('stdin_port' in cinfo)
50 50 self.assertTrue('iopub_port' in cinfo)
51 stream = km.create_iopub_stream(kid)
52 stream.close()
51 53 self.assertTrue('shell_port' in cinfo)
54 stream = km.create_shell_stream(kid)
55 stream.close()
52 56 self.assertTrue('hb_port' in cinfo)
57 stream = km.create_hb_stream(kid)
58 stream.close()
53 59 km.shutdown_kernel(kid)
54 60
55 61 def test_tcp_lifecycle(self):
56 62 km = self._get_tcp_km()
57 63 self._run_lifecycle(km)
58 64
59 65 def test_tcp_cinfo(self):
60 66 km = self._get_tcp_km()
61 67 self._run_cinfo(km, 'tcp', '127.0.0.1')
62 68
63 69 def test_ipc_lifecycle(self):
64 70 km = self._get_ipc_km()
65 71 self._run_lifecycle(km)
66 72
67 73 def test_ipc_cinfo(self):
68 74 km = self._get_ipc_km()
69 75 self._run_cinfo(km, 'ipc', 'test')
70 76
General Comments 0
You need to be logged in to leave comments. Login now