Show More
@@ -24,6 +24,9 from IPython.utils.traitlets import ( | |||||
24 | # Global setup and utilities |
|
24 | # Global setup and utilities | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 |
|
26 | |||
|
27 | STARTUP_TIMEOUT = 60 | |||
|
28 | TIMEOUT = 15 | |||
|
29 | ||||
27 | def setup(): |
|
30 | def setup(): | |
28 | global KM, KC |
|
31 | global KM, KC | |
29 | KM = KernelManager() |
|
32 | KM = KernelManager() | |
@@ -33,11 +36,11 def setup(): | |||||
33 |
|
36 | |||
34 | # wait for kernel to be ready |
|
37 | # wait for kernel to be ready | |
35 | try: |
|
38 | try: | |
36 |
msg = KC.iopub_channel.get_msg(block=True, timeout= |
|
39 | msg = KC.iopub_channel.get_msg(block=True, timeout=STARTUP_TIMEOUT) | |
37 | except Empty: |
|
40 | except Empty: | |
38 | pass |
|
41 | pass | |
39 | KC.execute("pass") |
|
42 | msg_id = KC.kernel_info() | |
40 |
KC.get_shell_msg(block=True, timeout= |
|
43 | KC.get_shell_msg(block=True, timeout=STARTUP_TIMEOUT) | |
41 | flush_channels() |
|
44 | flush_channels() | |
42 |
|
45 | |||
43 |
|
46 | |||
@@ -63,14 +66,14 def flush_channels(kc=None): | |||||
63 | def execute(code='', kc=None, **kwargs): |
|
66 | def execute(code='', kc=None, **kwargs): | |
64 | """wrapper for doing common steps for validating an execution request""" |
|
67 | """wrapper for doing common steps for validating an execution request""" | |
65 | msg_id = KC.execute(code=code, **kwargs) |
|
68 | msg_id = KC.execute(code=code, **kwargs) | |
66 |
reply = KC.get_shell_msg(timeout= |
|
69 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
67 | list(validate_message(reply, 'execute_reply', msg_id)) |
|
70 | list(validate_message(reply, 'execute_reply', msg_id)) | |
68 |
busy = KC.get_iopub_msg(timeout= |
|
71 | busy = KC.get_iopub_msg(timeout=TIMEOUT) | |
69 | list(validate_message(busy, 'status', msg_id)) |
|
72 | list(validate_message(busy, 'status', msg_id)) | |
70 | nt.assert_equal(busy['content']['execution_state'], 'busy') |
|
73 | nt.assert_equal(busy['content']['execution_state'], 'busy') | |
71 |
|
74 | |||
72 | if not kwargs.get('silent'): |
|
75 | if not kwargs.get('silent'): | |
73 |
pyin = KC.get_iopub_msg(timeout= |
|
76 | pyin = KC.get_iopub_msg(timeout=TIMEOUT) | |
74 | list(validate_message(pyin, 'pyin', msg_id)) |
|
77 | list(validate_message(pyin, 'pyin', msg_id)) | |
75 | nt.assert_equal(pyin['content']['code'], code) |
|
78 | nt.assert_equal(pyin['content']['code'], code) | |
76 |
|
79 | |||
@@ -297,7 +300,7 def test_execute(): | |||||
297 | flush_channels() |
|
300 | flush_channels() | |
298 |
|
301 | |||
299 | msg_id = KC.execute(code='x=1') |
|
302 | msg_id = KC.execute(code='x=1') | |
300 |
reply = KC.get_shell_msg(timeout= |
|
303 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
301 | for tst in validate_message(reply, 'execute_reply', msg_id): |
|
304 | for tst in validate_message(reply, 'execute_reply', msg_id): | |
302 | yield tst |
|
305 | yield tst | |
303 |
|
306 | |||
@@ -308,7 +311,7 def test_execute_silent(): | |||||
308 | msg_id, reply = execute(code='x=1', silent=True) |
|
311 | msg_id, reply = execute(code='x=1', silent=True) | |
309 |
|
312 | |||
310 | # flush status=idle |
|
313 | # flush status=idle | |
311 |
status = KC.iopub_channel.get_msg(timeout= |
|
314 | status = KC.iopub_channel.get_msg(timeout=TIMEOUT) | |
312 | for tst in validate_message(status, 'status', msg_id): |
|
315 | for tst in validate_message(status, 'status', msg_id): | |
313 | yield tst |
|
316 | yield tst | |
314 | nt.assert_equal(status['content']['execution_state'], 'idle') |
|
317 | nt.assert_equal(status['content']['execution_state'], 'idle') | |
@@ -319,7 +322,7 def test_execute_silent(): | |||||
319 | msg_id, reply = execute(code='x=2', silent=True) |
|
322 | msg_id, reply = execute(code='x=2', silent=True) | |
320 |
|
323 | |||
321 | # flush status=idle |
|
324 | # flush status=idle | |
322 |
status = KC.iopub_channel.get_msg(timeout= |
|
325 | status = KC.iopub_channel.get_msg(timeout=TIMEOUT) | |
323 | for tst in validate_message(status, 'status', msg_id): |
|
326 | for tst in validate_message(status, 'status', msg_id): | |
324 | yield tst |
|
327 | yield tst | |
325 | yield nt.assert_equal(status['content']['execution_state'], 'idle') |
|
328 | yield nt.assert_equal(status['content']['execution_state'], 'idle') | |
@@ -337,7 +340,7 def test_execute_error(): | |||||
337 | yield nt.assert_equal(reply['status'], 'error') |
|
340 | yield nt.assert_equal(reply['status'], 'error') | |
338 | yield nt.assert_equal(reply['ename'], 'ZeroDivisionError') |
|
341 | yield nt.assert_equal(reply['ename'], 'ZeroDivisionError') | |
339 |
|
342 | |||
340 |
pyerr = KC.iopub_channel.get_msg(timeout= |
|
343 | pyerr = KC.iopub_channel.get_msg(timeout=TIMEOUT) | |
341 | for tst in validate_message(pyerr, 'pyerr', msg_id): |
|
344 | for tst in validate_message(pyerr, 'pyerr', msg_id): | |
342 | yield tst |
|
345 | yield tst | |
343 |
|
346 | |||
@@ -405,7 +408,7 def test_oinfo(): | |||||
405 | flush_channels() |
|
408 | flush_channels() | |
406 |
|
409 | |||
407 | msg_id = KC.object_info('a') |
|
410 | msg_id = KC.object_info('a') | |
408 |
reply = KC.get_shell_msg(timeout= |
|
411 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
409 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
412 | for tst in validate_message(reply, 'object_info_reply', msg_id): | |
410 | yield tst |
|
413 | yield tst | |
411 |
|
414 | |||
@@ -417,7 +420,7 def test_oinfo_found(): | |||||
417 | msg_id, reply = execute(code='a=5') |
|
420 | msg_id, reply = execute(code='a=5') | |
418 |
|
421 | |||
419 | msg_id = KC.object_info('a') |
|
422 | msg_id = KC.object_info('a') | |
420 |
reply = KC.get_shell_msg(timeout= |
|
423 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
421 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
424 | for tst in validate_message(reply, 'object_info_reply', msg_id): | |
422 | yield tst |
|
425 | yield tst | |
423 | content = reply['content'] |
|
426 | content = reply['content'] | |
@@ -433,7 +436,7 def test_oinfo_detail(): | |||||
433 | msg_id, reply = execute(code='ip=get_ipython()') |
|
436 | msg_id, reply = execute(code='ip=get_ipython()') | |
434 |
|
437 | |||
435 | msg_id = KC.object_info('ip.object_inspect', detail_level=2) |
|
438 | msg_id = KC.object_info('ip.object_inspect', detail_level=2) | |
436 |
reply = KC.get_shell_msg(timeout= |
|
439 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
437 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
440 | for tst in validate_message(reply, 'object_info_reply', msg_id): | |
438 | yield tst |
|
441 | yield tst | |
439 | content = reply['content'] |
|
442 | content = reply['content'] | |
@@ -448,7 +451,7 def test_oinfo_not_found(): | |||||
448 | flush_channels() |
|
451 | flush_channels() | |
449 |
|
452 | |||
450 | msg_id = KC.object_info('dne') |
|
453 | msg_id = KC.object_info('dne') | |
451 |
reply = KC.get_shell_msg(timeout= |
|
454 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
452 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
455 | for tst in validate_message(reply, 'object_info_reply', msg_id): | |
453 | yield tst |
|
456 | yield tst | |
454 | content = reply['content'] |
|
457 | content = reply['content'] | |
@@ -462,7 +465,7 def test_complete(): | |||||
462 | msg_id, reply = execute(code="alpha = albert = 5") |
|
465 | msg_id, reply = execute(code="alpha = albert = 5") | |
463 |
|
466 | |||
464 | msg_id = KC.complete('al', 'al', 2) |
|
467 | msg_id = KC.complete('al', 'al', 2) | |
465 |
reply = KC.get_shell_msg(timeout= |
|
468 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
466 | for tst in validate_message(reply, 'complete_reply', msg_id): |
|
469 | for tst in validate_message(reply, 'complete_reply', msg_id): | |
467 | yield tst |
|
470 | yield tst | |
468 | matches = reply['content']['matches'] |
|
471 | matches = reply['content']['matches'] | |
@@ -475,7 +478,7 def test_kernel_info_request(): | |||||
475 | flush_channels() |
|
478 | flush_channels() | |
476 |
|
479 | |||
477 | msg_id = KC.kernel_info() |
|
480 | msg_id = KC.kernel_info() | |
478 |
reply = KC.get_shell_msg(timeout= |
|
481 | reply = KC.get_shell_msg(timeout=TIMEOUT) | |
479 | for tst in validate_message(reply, 'kernel_info_reply', msg_id): |
|
482 | for tst in validate_message(reply, 'kernel_info_reply', msg_id): | |
480 | yield tst |
|
483 | yield tst | |
481 |
|
484 | |||
@@ -489,7 +492,7 def test_stream(): | |||||
489 |
|
492 | |||
490 | msg_id, reply = execute("print('hi')") |
|
493 | msg_id, reply = execute("print('hi')") | |
491 |
|
494 | |||
492 |
stdout = KC.iopub_channel.get_msg(timeout= |
|
495 | stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT) | |
493 | for tst in validate_message(stdout, 'stream', msg_id): |
|
496 | for tst in validate_message(stdout, 'stream', msg_id): | |
494 | yield tst |
|
497 | yield tst | |
495 | content = stdout['content'] |
|
498 | content = stdout['content'] | |
@@ -503,7 +506,7 def test_display_data(): | |||||
503 |
|
506 | |||
504 | msg_id, reply = execute("from IPython.core.display import display; display(1)") |
|
507 | msg_id, reply = execute("from IPython.core.display import display; display(1)") | |
505 |
|
508 | |||
506 |
display = KC.iopub_channel.get_msg(timeout= |
|
509 | display = KC.iopub_channel.get_msg(timeout=TIMEOUT) | |
507 | for tst in validate_message(display, 'display_data', parent=msg_id): |
|
510 | for tst in validate_message(display, 'display_data', parent=msg_id): | |
508 | yield tst |
|
511 | yield tst | |
509 | data = display['content']['data'] |
|
512 | data = display['content']['data'] |
@@ -29,6 +29,9 from IPython.utils import path, py3compat | |||||
29 | # Tests |
|
29 | # Tests | |
30 | #------------------------------------------------------------------------------- |
|
30 | #------------------------------------------------------------------------------- | |
31 |
|
31 | |||
|
32 | SETUP_TIMEOUT = 60 | |||
|
33 | TIMEOUT = 15 | |||
|
34 | ||||
32 | def setup(): |
|
35 | def setup(): | |
33 | """setup temporary IPYTHONDIR for tests""" |
|
36 | """setup temporary IPYTHONDIR for tests""" | |
34 | global IPYTHONDIR |
|
37 | global IPYTHONDIR | |
@@ -70,7 +73,9 def setup_kernel(cmd): | |||||
70 | ) |
|
73 | ) | |
71 | # wait for connection file to exist, timeout after 5s |
|
74 | # wait for connection file to exist, timeout after 5s | |
72 | tic = time.time() |
|
75 | tic = time.time() | |
73 |
while not os.path.exists(connection_file) |
|
76 | while not os.path.exists(connection_file) \ | |
|
77 | and kernel.poll() is None \ | |||
|
78 | and time.time() < tic + SETUP_TIMEOUT: | |||
74 | time.sleep(0.1) |
|
79 | time.sleep(0.1) | |
75 |
|
80 | |||
76 | if kernel.poll() is not None: |
|
81 | if kernel.poll() is not None: | |
@@ -108,18 +113,18 def test_embed_kernel_basic(): | |||||
108 | with setup_kernel(cmd) as client: |
|
113 | with setup_kernel(cmd) as client: | |
109 | # oinfo a (int) |
|
114 | # oinfo a (int) | |
110 | msg_id = client.object_info('a') |
|
115 | msg_id = client.object_info('a') | |
111 |
msg = client.get_shell_msg(block=True, timeout= |
|
116 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
112 | content = msg['content'] |
|
117 | content = msg['content'] | |
113 | nt.assert_true(content['found']) |
|
118 | nt.assert_true(content['found']) | |
114 |
|
119 | |||
115 | msg_id = client.execute("c=a*2") |
|
120 | msg_id = client.execute("c=a*2") | |
116 |
msg = client.get_shell_msg(block=True, timeout= |
|
121 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
117 | content = msg['content'] |
|
122 | content = msg['content'] | |
118 | nt.assert_equal(content['status'], u'ok') |
|
123 | nt.assert_equal(content['status'], u'ok') | |
119 |
|
124 | |||
120 | # oinfo c (should be 10) |
|
125 | # oinfo c (should be 10) | |
121 | msg_id = client.object_info('c') |
|
126 | msg_id = client.object_info('c') | |
122 |
msg = client.get_shell_msg(block=True, timeout= |
|
127 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
123 | content = msg['content'] |
|
128 | content = msg['content'] | |
124 | nt.assert_true(content['found']) |
|
129 | nt.assert_true(content['found']) | |
125 | nt.assert_equal(content['string_form'], u'10') |
|
130 | nt.assert_equal(content['string_form'], u'10') | |
@@ -139,21 +144,21 def test_embed_kernel_namespace(): | |||||
139 | with setup_kernel(cmd) as client: |
|
144 | with setup_kernel(cmd) as client: | |
140 | # oinfo a (int) |
|
145 | # oinfo a (int) | |
141 | msg_id = client.object_info('a') |
|
146 | msg_id = client.object_info('a') | |
142 |
msg = client.get_shell_msg(block=True, timeout= |
|
147 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
143 | content = msg['content'] |
|
148 | content = msg['content'] | |
144 | nt.assert_true(content['found']) |
|
149 | nt.assert_true(content['found']) | |
145 | nt.assert_equal(content['string_form'], u'5') |
|
150 | nt.assert_equal(content['string_form'], u'5') | |
146 |
|
151 | |||
147 | # oinfo b (str) |
|
152 | # oinfo b (str) | |
148 | msg_id = client.object_info('b') |
|
153 | msg_id = client.object_info('b') | |
149 |
msg = client.get_shell_msg(block=True, timeout= |
|
154 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
150 | content = msg['content'] |
|
155 | content = msg['content'] | |
151 | nt.assert_true(content['found']) |
|
156 | nt.assert_true(content['found']) | |
152 | nt.assert_equal(content['string_form'], u'hi there') |
|
157 | nt.assert_equal(content['string_form'], u'hi there') | |
153 |
|
158 | |||
154 | # oinfo c (undefined) |
|
159 | # oinfo c (undefined) | |
155 | msg_id = client.object_info('c') |
|
160 | msg_id = client.object_info('c') | |
156 |
msg = client.get_shell_msg(block=True, timeout= |
|
161 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
157 | content = msg['content'] |
|
162 | content = msg['content'] | |
158 | nt.assert_false(content['found']) |
|
163 | nt.assert_false(content['found']) | |
159 |
|
164 | |||
@@ -175,14 +180,14 def test_embed_kernel_reentrant(): | |||||
175 | with setup_kernel(cmd) as client: |
|
180 | with setup_kernel(cmd) as client: | |
176 | for i in range(5): |
|
181 | for i in range(5): | |
177 | msg_id = client.object_info('count') |
|
182 | msg_id = client.object_info('count') | |
178 |
msg = client.get_shell_msg(block=True, timeout= |
|
183 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
179 | content = msg['content'] |
|
184 | content = msg['content'] | |
180 | nt.assert_true(content['found']) |
|
185 | nt.assert_true(content['found']) | |
181 | nt.assert_equal(content['string_form'], unicode(i)) |
|
186 | nt.assert_equal(content['string_form'], unicode(i)) | |
182 |
|
187 | |||
183 | # exit from embed_kernel |
|
188 | # exit from embed_kernel | |
184 | client.execute("get_ipython().exit_now = True") |
|
189 | client.execute("get_ipython().exit_now = True") | |
185 |
msg = client.get_shell_msg(block=True, timeout= |
|
190 | msg = client.get_shell_msg(block=True, timeout=TIMEOUT) | |
186 | time.sleep(0.2) |
|
191 | time.sleep(0.2) | |
187 |
|
192 | |||
188 |
|
193 |
General Comments 0
You need to be logged in to leave comments.
Login now