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