##// END OF EJS Templates
update IPython.kernel.tests to new API
MinRK -
Show More
@@ -28,7 +28,6 b' class TestKernelManager(TestCase):'
28 def _run_lifecycle(self, km):
28 def _run_lifecycle(self, km):
29 km.start_kernel(stdout=PIPE, stderr=PIPE)
29 km.start_kernel(stdout=PIPE, stderr=PIPE)
30 self.assertTrue(km.is_alive())
30 self.assertTrue(km.is_alive())
31 km.start_channels(shell=True, iopub=False, stdin=False, hb=False)
32 km.restart_kernel()
31 km.restart_kernel()
33 self.assertTrue(km.is_alive())
32 self.assertTrue(km.is_alive())
34 # We need a delay here to give the restarting kernel a chance to
33 # We need a delay here to give the restarting kernel a chance to
@@ -41,7 +40,6 b' class TestKernelManager(TestCase):'
41 km.interrupt_kernel()
40 km.interrupt_kernel()
42 self.assertTrue(isinstance(km, KernelManager))
41 self.assertTrue(isinstance(km, KernelManager))
43 km.shutdown_kernel()
42 km.shutdown_kernel()
44 km.shell_channel.stop()
45
43
46 def test_tcp_lifecycle(self):
44 def test_tcp_lifecycle(self):
47 km = self._get_tcp_km()
45 km = self._get_tcp_km()
@@ -15,7 +15,7 b' from Queue import Empty'
15
15
16 import nose.tools as nt
16 import nose.tools as nt
17
17
18 from IPython.kernel.blocking import BlockingKernelManager
18 from IPython.kernel import KernelManager, BlockingKernelClient
19
19
20
20
21 from IPython.testing import decorators as dec
21 from IPython.testing import decorators as dec
@@ -29,28 +29,29 b' from IPython.utils.traitlets import ('
29 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
30
30
31 def setup():
31 def setup():
32 global KM
32 global KM, KC
33 KM = BlockingKernelManager()
33 KM = KernelManager()
34
35 KM.start_kernel(stdout=PIPE, stderr=PIPE)
34 KM.start_kernel(stdout=PIPE, stderr=PIPE)
36 KM.start_channels()
35 KC = BlockingKernelClient(connection_file=KM.connection_file)
36 KC.load_connection_file()
37 KC.start_channels()
37
38
38 # wait for kernel to be ready
39 # wait for kernel to be ready
39 KM.shell_channel.execute("pass")
40 KC.shell_channel.execute("pass")
40 KM.shell_channel.get_msg(block=True, timeout=5)
41 KC.shell_channel.get_msg(block=True, timeout=5)
41 flush_channels()
42 flush_channels()
42
43
43
44
44 def teardown():
45 def teardown():
45 KM.stop_channels()
46 KC.stop_channels()
46 KM.shutdown_kernel()
47 KM.shutdown_kernel()
47
48
48
49
49 def flush_channels(km=None):
50 def flush_channels(kc=None):
50 if km is None:
51 km = KM
52 """flush any messages waiting on the queue"""
51 """flush any messages waiting on the queue"""
53 for channel in (km.shell_channel, km.iopub_channel):
52 if kc is None:
53 kc = KC
54 for channel in (kc.shell_channel, kc.iopub_channel):
54 while True:
55 while True:
55 try:
56 try:
56 msg = channel.get_msg(block=True, timeout=0.1)
57 msg = channel.get_msg(block=True, timeout=0.1)
@@ -60,12 +61,12 b' def flush_channels(km=None):'
60 list(validate_message(msg))
61 list(validate_message(msg))
61
62
62
63
63 def execute(code='', km=None, **kwargs):
64 def execute(code='', kc=None, **kwargs):
64 """wrapper for doing common steps for validating an execution request"""
65 """wrapper for doing common steps for validating an execution request"""
65 if km is None:
66 if kc is None:
66 km = KM
67 kc = KC
67 shell = km.shell_channel
68 shell = kc.shell_channel
68 sub = km.iopub_channel
69 sub = kc.iopub_channel
69
70
70 msg_id = shell.execute(code=code, **kwargs)
71 msg_id = shell.execute(code=code, **kwargs)
71 reply = shell.get_msg(timeout=2)
72 reply = shell.get_msg(timeout=2)
@@ -301,7 +302,7 b' def validate_message(msg, msg_type=None, parent=None):'
301 def test_execute():
302 def test_execute():
302 flush_channels()
303 flush_channels()
303
304
304 shell = KM.shell_channel
305 shell = KC.shell_channel
305 msg_id = shell.execute(code='x=1')
306 msg_id = shell.execute(code='x=1')
306 reply = shell.get_msg(timeout=2)
307 reply = shell.get_msg(timeout=2)
307 for tst in validate_message(reply, 'execute_reply', msg_id):
308 for tst in validate_message(reply, 'execute_reply', msg_id):
@@ -314,23 +315,23 b' def test_execute_silent():'
314 msg_id, reply = execute(code='x=1', silent=True)
315 msg_id, reply = execute(code='x=1', silent=True)
315
316
316 # flush status=idle
317 # flush status=idle
317 status = KM.iopub_channel.get_msg(timeout=2)
318 status = KC.iopub_channel.get_msg(timeout=2)
318 for tst in validate_message(status, 'status', msg_id):
319 for tst in validate_message(status, 'status', msg_id):
319 yield tst
320 yield tst
320 nt.assert_equal(status['content']['execution_state'], 'idle')
321 nt.assert_equal(status['content']['execution_state'], 'idle')
321
322
322 yield nt.assert_raises(Empty, KM.iopub_channel.get_msg, timeout=0.1)
323 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
323 count = reply['execution_count']
324 count = reply['execution_count']
324
325
325 msg_id, reply = execute(code='x=2', silent=True)
326 msg_id, reply = execute(code='x=2', silent=True)
326
327
327 # flush status=idle
328 # flush status=idle
328 status = KM.iopub_channel.get_msg(timeout=2)
329 status = KC.iopub_channel.get_msg(timeout=2)
329 for tst in validate_message(status, 'status', msg_id):
330 for tst in validate_message(status, 'status', msg_id):
330 yield tst
331 yield tst
331 yield nt.assert_equal(status['content']['execution_state'], 'idle')
332 yield nt.assert_equal(status['content']['execution_state'], 'idle')
332
333
333 yield nt.assert_raises(Empty, KM.iopub_channel.get_msg, timeout=0.1)
334 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
334 count_2 = reply['execution_count']
335 count_2 = reply['execution_count']
335 yield nt.assert_equal(count_2, count)
336 yield nt.assert_equal(count_2, count)
336
337
@@ -343,7 +344,7 b' def test_execute_error():'
343 yield nt.assert_equal(reply['status'], 'error')
344 yield nt.assert_equal(reply['status'], 'error')
344 yield nt.assert_equal(reply['ename'], 'ZeroDivisionError')
345 yield nt.assert_equal(reply['ename'], 'ZeroDivisionError')
345
346
346 pyerr = KM.iopub_channel.get_msg(timeout=2)
347 pyerr = KC.iopub_channel.get_msg(timeout=2)
347 for tst in validate_message(pyerr, 'pyerr', msg_id):
348 for tst in validate_message(pyerr, 'pyerr', msg_id):
348 yield tst
349 yield tst
349
350
@@ -382,7 +383,7 b' def test_user_expressions():'
382 def test_oinfo():
383 def test_oinfo():
383 flush_channels()
384 flush_channels()
384
385
385 shell = KM.shell_channel
386 shell = KC.shell_channel
386
387
387 msg_id = shell.object_info('a')
388 msg_id = shell.object_info('a')
388 reply = shell.get_msg(timeout=2)
389 reply = shell.get_msg(timeout=2)
@@ -394,7 +395,7 b' def test_oinfo():'
394 def test_oinfo_found():
395 def test_oinfo_found():
395 flush_channels()
396 flush_channels()
396
397
397 shell = KM.shell_channel
398 shell = KC.shell_channel
398
399
399 msg_id, reply = execute(code='a=5')
400 msg_id, reply = execute(code='a=5')
400
401
@@ -412,7 +413,7 b' def test_oinfo_found():'
412 def test_oinfo_detail():
413 def test_oinfo_detail():
413 flush_channels()
414 flush_channels()
414
415
415 shell = KM.shell_channel
416 shell = KC.shell_channel
416
417
417 msg_id, reply = execute(code='ip=get_ipython()')
418 msg_id, reply = execute(code='ip=get_ipython()')
418
419
@@ -431,7 +432,7 b' def test_oinfo_detail():'
431 def test_oinfo_not_found():
432 def test_oinfo_not_found():
432 flush_channels()
433 flush_channels()
433
434
434 shell = KM.shell_channel
435 shell = KC.shell_channel
435
436
436 msg_id = shell.object_info('dne')
437 msg_id = shell.object_info('dne')
437 reply = shell.get_msg(timeout=2)
438 reply = shell.get_msg(timeout=2)
@@ -445,7 +446,7 b' def test_oinfo_not_found():'
445 def test_complete():
446 def test_complete():
446 flush_channels()
447 flush_channels()
447
448
448 shell = KM.shell_channel
449 shell = KC.shell_channel
449
450
450 msg_id, reply = execute(code="alpha = albert = 5")
451 msg_id, reply = execute(code="alpha = albert = 5")
451
452
@@ -462,7 +463,7 b' def test_complete():'
462 def test_kernel_info_request():
463 def test_kernel_info_request():
463 flush_channels()
464 flush_channels()
464
465
465 shell = KM.shell_channel
466 shell = KC.shell_channel
466
467
467 msg_id = shell.kernel_info()
468 msg_id = shell.kernel_info()
468 reply = shell.get_msg(timeout=2)
469 reply = shell.get_msg(timeout=2)
@@ -479,7 +480,7 b' def test_stream():'
479
480
480 msg_id, reply = execute("print('hi')")
481 msg_id, reply = execute("print('hi')")
481
482
482 stdout = KM.iopub_channel.get_msg(timeout=2)
483 stdout = KC.iopub_channel.get_msg(timeout=2)
483 for tst in validate_message(stdout, 'stream', msg_id):
484 for tst in validate_message(stdout, 'stream', msg_id):
484 yield tst
485 yield tst
485 content = stdout['content']
486 content = stdout['content']
@@ -493,7 +494,7 b' def test_display_data():'
493
494
494 msg_id, reply = execute("from IPython.core.display import display; display(1)")
495 msg_id, reply = execute("from IPython.core.display import display; display(1)")
495
496
496 display = KM.iopub_channel.get_msg(timeout=2)
497 display = KC.iopub_channel.get_msg(timeout=2)
497 for tst in validate_message(display, 'display_data', parent=msg_id):
498 for tst in validate_message(display, 'display_data', parent=msg_id):
498 yield tst
499 yield tst
499 data = display['content']['data']
500 data = display['content']['data']
@@ -25,11 +25,17 b' from IPython import kernel'
25
25
26 @dec.parametric
26 @dec.parametric
27 def test_kms():
27 def test_kms():
28 for base in ("", "Blocking", "Multi"):
28 for base in ("", "Multi"):
29 KM = base + "KernelManager"
29 KM = base + "KernelManager"
30 yield nt.assert_true(KM in dir(kernel), KM)
30 yield nt.assert_true(KM in dir(kernel), KM)
31
31
32 @dec.parametric
32 @dec.parametric
33 def test_kcs():
34 for base in ("", "Blocking"):
35 KM = base + "KernelClient"
36 yield nt.assert_true(KM in dir(kernel), KM)
37
38 @dec.parametric
33 def test_launcher():
39 def test_launcher():
34 for name in launcher.__all__:
40 for name in launcher.__all__:
35 yield nt.assert_true(name in dir(kernel), name)
41 yield nt.assert_true(name in dir(kernel), name)
General Comments 0
You need to be logged in to leave comments. Login now