##// END OF EJS Templates
Merge pull request #3641 from minrk/travisempty...
Min RK -
r11441:c6d64922 merge
parent child Browse files
Show More
@@ -1,507 +1,511 b''
1 """Test suite for our zeromq-based messaging specification.
1 """Test suite for our zeromq-based messaging specification.
2 """
2 """
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2010-2011 The IPython Development Team
4 # Copyright (C) 2010-2011 The IPython Development Team
5 #
5 #
6 # Distributed under the terms of the BSD License. The full license is in
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING.txt, distributed as part of this software.
7 # the file COPYING.txt, distributed as part of this software.
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9
9
10 import re
10 import re
11 from subprocess import PIPE
11 from subprocess import PIPE
12 from Queue import Empty
12 from Queue import Empty
13
13
14 import nose.tools as nt
14 import nose.tools as nt
15
15
16 from IPython.kernel import KernelManager
16 from IPython.kernel import KernelManager
17
17
18 from IPython.testing import decorators as dec
18 from IPython.testing import decorators as dec
19 from IPython.utils.traitlets import (
19 from IPython.utils.traitlets import (
20 HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum, Any,
20 HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum, Any,
21 )
21 )
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Global setup and utilities
24 # Global setup and utilities
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27 def setup():
27 def setup():
28 global KM, KC
28 global KM, KC
29 KM = KernelManager()
29 KM = KernelManager()
30 KM.start_kernel(stdout=PIPE, stderr=PIPE)
30 KM.start_kernel(stdout=PIPE, stderr=PIPE)
31 KC = KM.client()
31 KC = KM.client()
32 KC.start_channels()
32 KC.start_channels()
33
33
34 # wait for kernel to be ready
34 # wait for kernel to be ready
35 try:
36 msg = KC.iopub_channel.get_msg(block=True, timeout=10)
37 except Empty:
38 pass
35 KC.execute("pass")
39 KC.execute("pass")
36 KC.get_shell_msg(block=True, timeout=5)
40 KC.get_shell_msg(block=True, timeout=5)
37 flush_channels()
41 flush_channels()
38
42
39
43
40 def teardown():
44 def teardown():
41 KC.stop_channels()
45 KC.stop_channels()
42 KM.shutdown_kernel()
46 KM.shutdown_kernel()
43
47
44
48
45 def flush_channels(kc=None):
49 def flush_channels(kc=None):
46 """flush any messages waiting on the queue"""
50 """flush any messages waiting on the queue"""
47 if kc is None:
51 if kc is None:
48 kc = KC
52 kc = KC
49 for channel in (kc.shell_channel, kc.iopub_channel):
53 for channel in (kc.shell_channel, kc.iopub_channel):
50 while True:
54 while True:
51 try:
55 try:
52 msg = channel.get_msg(block=True, timeout=0.1)
56 msg = channel.get_msg(block=True, timeout=0.1)
53 except Empty:
57 except Empty:
54 break
58 break
55 else:
59 else:
56 list(validate_message(msg))
60 list(validate_message(msg))
57
61
58
62
59 def execute(code='', kc=None, **kwargs):
63 def execute(code='', kc=None, **kwargs):
60 """wrapper for doing common steps for validating an execution request"""
64 """wrapper for doing common steps for validating an execution request"""
61 msg_id = KC.execute(code=code, **kwargs)
65 msg_id = KC.execute(code=code, **kwargs)
62 reply = KC.get_shell_msg(timeout=2)
66 reply = KC.get_shell_msg(timeout=2)
63 list(validate_message(reply, 'execute_reply', msg_id))
67 list(validate_message(reply, 'execute_reply', msg_id))
64 busy = KC.get_iopub_msg(timeout=2)
68 busy = KC.get_iopub_msg(timeout=2)
65 list(validate_message(busy, 'status', msg_id))
69 list(validate_message(busy, 'status', msg_id))
66 nt.assert_equal(busy['content']['execution_state'], 'busy')
70 nt.assert_equal(busy['content']['execution_state'], 'busy')
67
71
68 if not kwargs.get('silent'):
72 if not kwargs.get('silent'):
69 pyin = KC.get_iopub_msg(timeout=2)
73 pyin = KC.get_iopub_msg(timeout=2)
70 list(validate_message(pyin, 'pyin', msg_id))
74 list(validate_message(pyin, 'pyin', msg_id))
71 nt.assert_equal(pyin['content']['code'], code)
75 nt.assert_equal(pyin['content']['code'], code)
72
76
73 return msg_id, reply['content']
77 return msg_id, reply['content']
74
78
75 #-----------------------------------------------------------------------------
79 #-----------------------------------------------------------------------------
76 # MSG Spec References
80 # MSG Spec References
77 #-----------------------------------------------------------------------------
81 #-----------------------------------------------------------------------------
78
82
79
83
80 class Reference(HasTraits):
84 class Reference(HasTraits):
81
85
82 """
86 """
83 Base class for message spec specification testing.
87 Base class for message spec specification testing.
84
88
85 This class is the core of the message specification test. The
89 This class is the core of the message specification test. The
86 idea is that child classes implement trait attributes for each
90 idea is that child classes implement trait attributes for each
87 message keys, so that message keys can be tested against these
91 message keys, so that message keys can be tested against these
88 traits using :meth:`check` method.
92 traits using :meth:`check` method.
89
93
90 """
94 """
91
95
92 def check(self, d):
96 def check(self, d):
93 """validate a dict against our traits"""
97 """validate a dict against our traits"""
94 for key in self.trait_names():
98 for key in self.trait_names():
95 yield nt.assert_true(key in d, "Missing key: %r, should be found in %s" % (key, d))
99 yield nt.assert_true(key in d, "Missing key: %r, should be found in %s" % (key, d))
96 # FIXME: always allow None, probably not a good idea
100 # FIXME: always allow None, probably not a good idea
97 if d[key] is None:
101 if d[key] is None:
98 continue
102 continue
99 try:
103 try:
100 setattr(self, key, d[key])
104 setattr(self, key, d[key])
101 except TraitError as e:
105 except TraitError as e:
102 yield nt.assert_true(False, str(e))
106 yield nt.assert_true(False, str(e))
103
107
104
108
105 class RMessage(Reference):
109 class RMessage(Reference):
106 msg_id = Unicode()
110 msg_id = Unicode()
107 msg_type = Unicode()
111 msg_type = Unicode()
108 header = Dict()
112 header = Dict()
109 parent_header = Dict()
113 parent_header = Dict()
110 content = Dict()
114 content = Dict()
111
115
112 class RHeader(Reference):
116 class RHeader(Reference):
113 msg_id = Unicode()
117 msg_id = Unicode()
114 msg_type = Unicode()
118 msg_type = Unicode()
115 session = Unicode()
119 session = Unicode()
116 username = Unicode()
120 username = Unicode()
117
121
118 class RContent(Reference):
122 class RContent(Reference):
119 status = Enum((u'ok', u'error'))
123 status = Enum((u'ok', u'error'))
120
124
121
125
122 class ExecuteReply(Reference):
126 class ExecuteReply(Reference):
123 execution_count = Integer()
127 execution_count = Integer()
124 status = Enum((u'ok', u'error'))
128 status = Enum((u'ok', u'error'))
125
129
126 def check(self, d):
130 def check(self, d):
127 for tst in Reference.check(self, d):
131 for tst in Reference.check(self, d):
128 yield tst
132 yield tst
129 if d['status'] == 'ok':
133 if d['status'] == 'ok':
130 for tst in ExecuteReplyOkay().check(d):
134 for tst in ExecuteReplyOkay().check(d):
131 yield tst
135 yield tst
132 elif d['status'] == 'error':
136 elif d['status'] == 'error':
133 for tst in ExecuteReplyError().check(d):
137 for tst in ExecuteReplyError().check(d):
134 yield tst
138 yield tst
135
139
136
140
137 class ExecuteReplyOkay(Reference):
141 class ExecuteReplyOkay(Reference):
138 payload = List(Dict)
142 payload = List(Dict)
139 user_variables = Dict()
143 user_variables = Dict()
140 user_expressions = Dict()
144 user_expressions = Dict()
141
145
142
146
143 class ExecuteReplyError(Reference):
147 class ExecuteReplyError(Reference):
144 ename = Unicode()
148 ename = Unicode()
145 evalue = Unicode()
149 evalue = Unicode()
146 traceback = List(Unicode)
150 traceback = List(Unicode)
147
151
148
152
149 class OInfoReply(Reference):
153 class OInfoReply(Reference):
150 name = Unicode()
154 name = Unicode()
151 found = Bool()
155 found = Bool()
152 ismagic = Bool()
156 ismagic = Bool()
153 isalias = Bool()
157 isalias = Bool()
154 namespace = Enum((u'builtin', u'magics', u'alias', u'Interactive'))
158 namespace = Enum((u'builtin', u'magics', u'alias', u'Interactive'))
155 type_name = Unicode()
159 type_name = Unicode()
156 string_form = Unicode()
160 string_form = Unicode()
157 base_class = Unicode()
161 base_class = Unicode()
158 length = Integer()
162 length = Integer()
159 file = Unicode()
163 file = Unicode()
160 definition = Unicode()
164 definition = Unicode()
161 argspec = Dict()
165 argspec = Dict()
162 init_definition = Unicode()
166 init_definition = Unicode()
163 docstring = Unicode()
167 docstring = Unicode()
164 init_docstring = Unicode()
168 init_docstring = Unicode()
165 class_docstring = Unicode()
169 class_docstring = Unicode()
166 call_def = Unicode()
170 call_def = Unicode()
167 call_docstring = Unicode()
171 call_docstring = Unicode()
168 source = Unicode()
172 source = Unicode()
169
173
170 def check(self, d):
174 def check(self, d):
171 for tst in Reference.check(self, d):
175 for tst in Reference.check(self, d):
172 yield tst
176 yield tst
173 if d['argspec'] is not None:
177 if d['argspec'] is not None:
174 for tst in ArgSpec().check(d['argspec']):
178 for tst in ArgSpec().check(d['argspec']):
175 yield tst
179 yield tst
176
180
177
181
178 class ArgSpec(Reference):
182 class ArgSpec(Reference):
179 args = List(Unicode)
183 args = List(Unicode)
180 varargs = Unicode()
184 varargs = Unicode()
181 varkw = Unicode()
185 varkw = Unicode()
182 defaults = List()
186 defaults = List()
183
187
184
188
185 class Status(Reference):
189 class Status(Reference):
186 execution_state = Enum((u'busy', u'idle', u'starting'))
190 execution_state = Enum((u'busy', u'idle', u'starting'))
187
191
188
192
189 class CompleteReply(Reference):
193 class CompleteReply(Reference):
190 matches = List(Unicode)
194 matches = List(Unicode)
191
195
192
196
193 def Version(num, trait=Integer):
197 def Version(num, trait=Integer):
194 return List(trait, default_value=[0] * num, minlen=num, maxlen=num)
198 return List(trait, default_value=[0] * num, minlen=num, maxlen=num)
195
199
196
200
197 class KernelInfoReply(Reference):
201 class KernelInfoReply(Reference):
198
202
199 protocol_version = Version(2)
203 protocol_version = Version(2)
200 ipython_version = Version(4, Any)
204 ipython_version = Version(4, Any)
201 language_version = Version(3)
205 language_version = Version(3)
202 language = Unicode()
206 language = Unicode()
203
207
204 def _ipython_version_changed(self, name, old, new):
208 def _ipython_version_changed(self, name, old, new):
205 for v in new:
209 for v in new:
206 nt.assert_true(
210 nt.assert_true(
207 isinstance(v, int) or isinstance(v, basestring),
211 isinstance(v, int) or isinstance(v, basestring),
208 'expected int or string as version component, got {0!r}'
212 'expected int or string as version component, got {0!r}'
209 .format(v))
213 .format(v))
210
214
211
215
212 # IOPub messages
216 # IOPub messages
213
217
214 class PyIn(Reference):
218 class PyIn(Reference):
215 code = Unicode()
219 code = Unicode()
216 execution_count = Integer()
220 execution_count = Integer()
217
221
218
222
219 PyErr = ExecuteReplyError
223 PyErr = ExecuteReplyError
220
224
221
225
222 class Stream(Reference):
226 class Stream(Reference):
223 name = Enum((u'stdout', u'stderr'))
227 name = Enum((u'stdout', u'stderr'))
224 data = Unicode()
228 data = Unicode()
225
229
226
230
227 mime_pat = re.compile(r'\w+/\w+')
231 mime_pat = re.compile(r'\w+/\w+')
228
232
229 class DisplayData(Reference):
233 class DisplayData(Reference):
230 source = Unicode()
234 source = Unicode()
231 metadata = Dict()
235 metadata = Dict()
232 data = Dict()
236 data = Dict()
233 def _data_changed(self, name, old, new):
237 def _data_changed(self, name, old, new):
234 for k,v in new.iteritems():
238 for k,v in new.iteritems():
235 nt.assert_true(mime_pat.match(k))
239 nt.assert_true(mime_pat.match(k))
236 nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v)
240 nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v)
237
241
238
242
239 class PyOut(Reference):
243 class PyOut(Reference):
240 execution_count = Integer()
244 execution_count = Integer()
241 data = Dict()
245 data = Dict()
242 def _data_changed(self, name, old, new):
246 def _data_changed(self, name, old, new):
243 for k,v in new.iteritems():
247 for k,v in new.iteritems():
244 nt.assert_true(mime_pat.match(k))
248 nt.assert_true(mime_pat.match(k))
245 nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v)
249 nt.assert_true(isinstance(v, basestring), "expected string data, got %r" % v)
246
250
247
251
248 references = {
252 references = {
249 'execute_reply' : ExecuteReply(),
253 'execute_reply' : ExecuteReply(),
250 'object_info_reply' : OInfoReply(),
254 'object_info_reply' : OInfoReply(),
251 'status' : Status(),
255 'status' : Status(),
252 'complete_reply' : CompleteReply(),
256 'complete_reply' : CompleteReply(),
253 'kernel_info_reply': KernelInfoReply(),
257 'kernel_info_reply': KernelInfoReply(),
254 'pyin' : PyIn(),
258 'pyin' : PyIn(),
255 'pyout' : PyOut(),
259 'pyout' : PyOut(),
256 'pyerr' : PyErr(),
260 'pyerr' : PyErr(),
257 'stream' : Stream(),
261 'stream' : Stream(),
258 'display_data' : DisplayData(),
262 'display_data' : DisplayData(),
259 }
263 }
260 """
264 """
261 Specifications of `content` part of the reply messages.
265 Specifications of `content` part of the reply messages.
262 """
266 """
263
267
264
268
265 def validate_message(msg, msg_type=None, parent=None):
269 def validate_message(msg, msg_type=None, parent=None):
266 """validate a message
270 """validate a message
267
271
268 This is a generator, and must be iterated through to actually
272 This is a generator, and must be iterated through to actually
269 trigger each test.
273 trigger each test.
270
274
271 If msg_type and/or parent are given, the msg_type and/or parent msg_id
275 If msg_type and/or parent are given, the msg_type and/or parent msg_id
272 are compared with the given values.
276 are compared with the given values.
273 """
277 """
274 RMessage().check(msg)
278 RMessage().check(msg)
275 if msg_type:
279 if msg_type:
276 yield nt.assert_equal(msg['msg_type'], msg_type)
280 yield nt.assert_equal(msg['msg_type'], msg_type)
277 if parent:
281 if parent:
278 yield nt.assert_equal(msg['parent_header']['msg_id'], parent)
282 yield nt.assert_equal(msg['parent_header']['msg_id'], parent)
279 content = msg['content']
283 content = msg['content']
280 ref = references[msg['msg_type']]
284 ref = references[msg['msg_type']]
281 for tst in ref.check(content):
285 for tst in ref.check(content):
282 yield tst
286 yield tst
283
287
284
288
285 #-----------------------------------------------------------------------------
289 #-----------------------------------------------------------------------------
286 # Tests
290 # Tests
287 #-----------------------------------------------------------------------------
291 #-----------------------------------------------------------------------------
288
292
289 # Shell channel
293 # Shell channel
290
294
291 @dec.parametric
295 @dec.parametric
292 def test_execute():
296 def test_execute():
293 flush_channels()
297 flush_channels()
294
298
295 msg_id = KC.execute(code='x=1')
299 msg_id = KC.execute(code='x=1')
296 reply = KC.get_shell_msg(timeout=2)
300 reply = KC.get_shell_msg(timeout=2)
297 for tst in validate_message(reply, 'execute_reply', msg_id):
301 for tst in validate_message(reply, 'execute_reply', msg_id):
298 yield tst
302 yield tst
299
303
300
304
301 @dec.parametric
305 @dec.parametric
302 def test_execute_silent():
306 def test_execute_silent():
303 flush_channels()
307 flush_channels()
304 msg_id, reply = execute(code='x=1', silent=True)
308 msg_id, reply = execute(code='x=1', silent=True)
305
309
306 # flush status=idle
310 # flush status=idle
307 status = KC.iopub_channel.get_msg(timeout=2)
311 status = KC.iopub_channel.get_msg(timeout=2)
308 for tst in validate_message(status, 'status', msg_id):
312 for tst in validate_message(status, 'status', msg_id):
309 yield tst
313 yield tst
310 nt.assert_equal(status['content']['execution_state'], 'idle')
314 nt.assert_equal(status['content']['execution_state'], 'idle')
311
315
312 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
316 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
313 count = reply['execution_count']
317 count = reply['execution_count']
314
318
315 msg_id, reply = execute(code='x=2', silent=True)
319 msg_id, reply = execute(code='x=2', silent=True)
316
320
317 # flush status=idle
321 # flush status=idle
318 status = KC.iopub_channel.get_msg(timeout=2)
322 status = KC.iopub_channel.get_msg(timeout=2)
319 for tst in validate_message(status, 'status', msg_id):
323 for tst in validate_message(status, 'status', msg_id):
320 yield tst
324 yield tst
321 yield nt.assert_equal(status['content']['execution_state'], 'idle')
325 yield nt.assert_equal(status['content']['execution_state'], 'idle')
322
326
323 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
327 yield nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
324 count_2 = reply['execution_count']
328 count_2 = reply['execution_count']
325 yield nt.assert_equal(count_2, count)
329 yield nt.assert_equal(count_2, count)
326
330
327
331
328 @dec.parametric
332 @dec.parametric
329 def test_execute_error():
333 def test_execute_error():
330 flush_channels()
334 flush_channels()
331
335
332 msg_id, reply = execute(code='1/0')
336 msg_id, reply = execute(code='1/0')
333 yield nt.assert_equal(reply['status'], 'error')
337 yield nt.assert_equal(reply['status'], 'error')
334 yield nt.assert_equal(reply['ename'], 'ZeroDivisionError')
338 yield nt.assert_equal(reply['ename'], 'ZeroDivisionError')
335
339
336 pyerr = KC.iopub_channel.get_msg(timeout=2)
340 pyerr = KC.iopub_channel.get_msg(timeout=2)
337 for tst in validate_message(pyerr, 'pyerr', msg_id):
341 for tst in validate_message(pyerr, 'pyerr', msg_id):
338 yield tst
342 yield tst
339
343
340
344
341 def test_execute_inc():
345 def test_execute_inc():
342 """execute request should increment execution_count"""
346 """execute request should increment execution_count"""
343 flush_channels()
347 flush_channels()
344
348
345 msg_id, reply = execute(code='x=1')
349 msg_id, reply = execute(code='x=1')
346 count = reply['execution_count']
350 count = reply['execution_count']
347
351
348 flush_channels()
352 flush_channels()
349
353
350 msg_id, reply = execute(code='x=2')
354 msg_id, reply = execute(code='x=2')
351 count_2 = reply['execution_count']
355 count_2 = reply['execution_count']
352 nt.assert_equal(count_2, count+1)
356 nt.assert_equal(count_2, count+1)
353
357
354
358
355 def test_user_variables():
359 def test_user_variables():
356 flush_channels()
360 flush_channels()
357
361
358 msg_id, reply = execute(code='x=1', user_variables=['x'])
362 msg_id, reply = execute(code='x=1', user_variables=['x'])
359 user_variables = reply['user_variables']
363 user_variables = reply['user_variables']
360 nt.assert_equal(user_variables, {u'x': {
364 nt.assert_equal(user_variables, {u'x': {
361 u'status': u'ok',
365 u'status': u'ok',
362 u'data': {u'text/plain': u'1'},
366 u'data': {u'text/plain': u'1'},
363 u'metadata': {},
367 u'metadata': {},
364 }})
368 }})
365
369
366
370
367 def test_user_variables_fail():
371 def test_user_variables_fail():
368 flush_channels()
372 flush_channels()
369
373
370 msg_id, reply = execute(code='x=1', user_variables=['nosuchname'])
374 msg_id, reply = execute(code='x=1', user_variables=['nosuchname'])
371 user_variables = reply['user_variables']
375 user_variables = reply['user_variables']
372 foo = user_variables['nosuchname']
376 foo = user_variables['nosuchname']
373 nt.assert_equal(foo['status'], 'error')
377 nt.assert_equal(foo['status'], 'error')
374 nt.assert_equal(foo['ename'], 'KeyError')
378 nt.assert_equal(foo['ename'], 'KeyError')
375
379
376
380
377 def test_user_expressions():
381 def test_user_expressions():
378 flush_channels()
382 flush_channels()
379
383
380 msg_id, reply = execute(code='x=1', user_expressions=dict(foo='x+1'))
384 msg_id, reply = execute(code='x=1', user_expressions=dict(foo='x+1'))
381 user_expressions = reply['user_expressions']
385 user_expressions = reply['user_expressions']
382 nt.assert_equal(user_expressions, {u'foo': {
386 nt.assert_equal(user_expressions, {u'foo': {
383 u'status': u'ok',
387 u'status': u'ok',
384 u'data': {u'text/plain': u'2'},
388 u'data': {u'text/plain': u'2'},
385 u'metadata': {},
389 u'metadata': {},
386 }})
390 }})
387
391
388
392
389 def test_user_expressions_fail():
393 def test_user_expressions_fail():
390 flush_channels()
394 flush_channels()
391
395
392 msg_id, reply = execute(code='x=0', user_expressions=dict(foo='nosuchname'))
396 msg_id, reply = execute(code='x=0', user_expressions=dict(foo='nosuchname'))
393 user_expressions = reply['user_expressions']
397 user_expressions = reply['user_expressions']
394 foo = user_expressions['foo']
398 foo = user_expressions['foo']
395 nt.assert_equal(foo['status'], 'error')
399 nt.assert_equal(foo['status'], 'error')
396 nt.assert_equal(foo['ename'], 'NameError')
400 nt.assert_equal(foo['ename'], 'NameError')
397
401
398
402
399 @dec.parametric
403 @dec.parametric
400 def test_oinfo():
404 def test_oinfo():
401 flush_channels()
405 flush_channels()
402
406
403 msg_id = KC.object_info('a')
407 msg_id = KC.object_info('a')
404 reply = KC.get_shell_msg(timeout=2)
408 reply = KC.get_shell_msg(timeout=2)
405 for tst in validate_message(reply, 'object_info_reply', msg_id):
409 for tst in validate_message(reply, 'object_info_reply', msg_id):
406 yield tst
410 yield tst
407
411
408
412
409 @dec.parametric
413 @dec.parametric
410 def test_oinfo_found():
414 def test_oinfo_found():
411 flush_channels()
415 flush_channels()
412
416
413 msg_id, reply = execute(code='a=5')
417 msg_id, reply = execute(code='a=5')
414
418
415 msg_id = KC.object_info('a')
419 msg_id = KC.object_info('a')
416 reply = KC.get_shell_msg(timeout=2)
420 reply = KC.get_shell_msg(timeout=2)
417 for tst in validate_message(reply, 'object_info_reply', msg_id):
421 for tst in validate_message(reply, 'object_info_reply', msg_id):
418 yield tst
422 yield tst
419 content = reply['content']
423 content = reply['content']
420 yield nt.assert_true(content['found'])
424 yield nt.assert_true(content['found'])
421 argspec = content['argspec']
425 argspec = content['argspec']
422 yield nt.assert_true(argspec is None, "didn't expect argspec dict, got %r" % argspec)
426 yield nt.assert_true(argspec is None, "didn't expect argspec dict, got %r" % argspec)
423
427
424
428
425 @dec.parametric
429 @dec.parametric
426 def test_oinfo_detail():
430 def test_oinfo_detail():
427 flush_channels()
431 flush_channels()
428
432
429 msg_id, reply = execute(code='ip=get_ipython()')
433 msg_id, reply = execute(code='ip=get_ipython()')
430
434
431 msg_id = KC.object_info('ip.object_inspect', detail_level=2)
435 msg_id = KC.object_info('ip.object_inspect', detail_level=2)
432 reply = KC.get_shell_msg(timeout=2)
436 reply = KC.get_shell_msg(timeout=2)
433 for tst in validate_message(reply, 'object_info_reply', msg_id):
437 for tst in validate_message(reply, 'object_info_reply', msg_id):
434 yield tst
438 yield tst
435 content = reply['content']
439 content = reply['content']
436 yield nt.assert_true(content['found'])
440 yield nt.assert_true(content['found'])
437 argspec = content['argspec']
441 argspec = content['argspec']
438 yield nt.assert_true(isinstance(argspec, dict), "expected non-empty argspec dict, got %r" % argspec)
442 yield nt.assert_true(isinstance(argspec, dict), "expected non-empty argspec dict, got %r" % argspec)
439 yield nt.assert_equal(argspec['defaults'], [0])
443 yield nt.assert_equal(argspec['defaults'], [0])
440
444
441
445
442 @dec.parametric
446 @dec.parametric
443 def test_oinfo_not_found():
447 def test_oinfo_not_found():
444 flush_channels()
448 flush_channels()
445
449
446 msg_id = KC.object_info('dne')
450 msg_id = KC.object_info('dne')
447 reply = KC.get_shell_msg(timeout=2)
451 reply = KC.get_shell_msg(timeout=2)
448 for tst in validate_message(reply, 'object_info_reply', msg_id):
452 for tst in validate_message(reply, 'object_info_reply', msg_id):
449 yield tst
453 yield tst
450 content = reply['content']
454 content = reply['content']
451 yield nt.assert_false(content['found'])
455 yield nt.assert_false(content['found'])
452
456
453
457
454 @dec.parametric
458 @dec.parametric
455 def test_complete():
459 def test_complete():
456 flush_channels()
460 flush_channels()
457
461
458 msg_id, reply = execute(code="alpha = albert = 5")
462 msg_id, reply = execute(code="alpha = albert = 5")
459
463
460 msg_id = KC.complete('al', 'al', 2)
464 msg_id = KC.complete('al', 'al', 2)
461 reply = KC.get_shell_msg(timeout=2)
465 reply = KC.get_shell_msg(timeout=2)
462 for tst in validate_message(reply, 'complete_reply', msg_id):
466 for tst in validate_message(reply, 'complete_reply', msg_id):
463 yield tst
467 yield tst
464 matches = reply['content']['matches']
468 matches = reply['content']['matches']
465 for name in ('alpha', 'albert'):
469 for name in ('alpha', 'albert'):
466 yield nt.assert_true(name in matches, "Missing match: %r" % name)
470 yield nt.assert_true(name in matches, "Missing match: %r" % name)
467
471
468
472
469 @dec.parametric
473 @dec.parametric
470 def test_kernel_info_request():
474 def test_kernel_info_request():
471 flush_channels()
475 flush_channels()
472
476
473 msg_id = KC.kernel_info()
477 msg_id = KC.kernel_info()
474 reply = KC.get_shell_msg(timeout=2)
478 reply = KC.get_shell_msg(timeout=2)
475 for tst in validate_message(reply, 'kernel_info_reply', msg_id):
479 for tst in validate_message(reply, 'kernel_info_reply', msg_id):
476 yield tst
480 yield tst
477
481
478
482
479 # IOPub channel
483 # IOPub channel
480
484
481
485
482 @dec.parametric
486 @dec.parametric
483 def test_stream():
487 def test_stream():
484 flush_channels()
488 flush_channels()
485
489
486 msg_id, reply = execute("print('hi')")
490 msg_id, reply = execute("print('hi')")
487
491
488 stdout = KC.iopub_channel.get_msg(timeout=2)
492 stdout = KC.iopub_channel.get_msg(timeout=2)
489 for tst in validate_message(stdout, 'stream', msg_id):
493 for tst in validate_message(stdout, 'stream', msg_id):
490 yield tst
494 yield tst
491 content = stdout['content']
495 content = stdout['content']
492 yield nt.assert_equal(content['name'], u'stdout')
496 yield nt.assert_equal(content['name'], u'stdout')
493 yield nt.assert_equal(content['data'], u'hi\n')
497 yield nt.assert_equal(content['data'], u'hi\n')
494
498
495
499
496 @dec.parametric
500 @dec.parametric
497 def test_display_data():
501 def test_display_data():
498 flush_channels()
502 flush_channels()
499
503
500 msg_id, reply = execute("from IPython.core.display import display; display(1)")
504 msg_id, reply = execute("from IPython.core.display import display; display(1)")
501
505
502 display = KC.iopub_channel.get_msg(timeout=2)
506 display = KC.iopub_channel.get_msg(timeout=2)
503 for tst in validate_message(display, 'display_data', parent=msg_id):
507 for tst in validate_message(display, 'display_data', parent=msg_id):
504 yield tst
508 yield tst
505 data = display['content']['data']
509 data = display['content']['data']
506 yield nt.assert_equal(data['text/plain'], u'1')
510 yield nt.assert_equal(data['text/plain'], u'1')
507
511
General Comments 0
You need to be logged in to leave comments. Login now