##// END OF EJS Templates
added history tests
Narahari -
Show More
@@ -1,443 +1,456 b''
1 """Test suite for our zeromq-based message specification."""
1 """Test suite for our zeromq-based message specification."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import re
6 import re
7 import sys
7 import sys
8 from distutils.version import LooseVersion as V
8 from distutils.version import LooseVersion as V
9 try:
9 try:
10 from queue import Empty # Py 3
10 from queue import Empty # Py 3
11 except ImportError:
11 except ImportError:
12 from Queue import Empty # Py 2
12 from Queue import Empty # Py 2
13
13
14 import nose.tools as nt
14 import nose.tools as nt
15
15
16 from IPython.utils.traitlets import (
16 from IPython.utils.traitlets import (
17 HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum,
17 HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum,
18 )
18 )
19 from IPython.utils.py3compat import string_types, iteritems
19 from IPython.utils.py3compat import string_types, iteritems
20
20
21 from .utils import TIMEOUT, start_global_kernel, flush_channels, execute
21 from .utils import TIMEOUT, start_global_kernel, flush_channels, execute
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Globals
24 # Globals
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26 KC = None
26 KC = None
27
27
28 def setup():
28 def setup():
29 global KC
29 global KC
30 KC = start_global_kernel()
30 KC = start_global_kernel()
31
31
32 #-----------------------------------------------------------------------------
32 #-----------------------------------------------------------------------------
33 # Message Spec References
33 # Message Spec References
34 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
35
35
36 class Reference(HasTraits):
36 class Reference(HasTraits):
37
37
38 """
38 """
39 Base class for message spec specification testing.
39 Base class for message spec specification testing.
40
40
41 This class is the core of the message specification test. The
41 This class is the core of the message specification test. The
42 idea is that child classes implement trait attributes for each
42 idea is that child classes implement trait attributes for each
43 message keys, so that message keys can be tested against these
43 message keys, so that message keys can be tested against these
44 traits using :meth:`check` method.
44 traits using :meth:`check` method.
45
45
46 """
46 """
47
47
48 def check(self, d):
48 def check(self, d):
49 """validate a dict against our traits"""
49 """validate a dict against our traits"""
50 for key in self.trait_names():
50 for key in self.trait_names():
51 nt.assert_in(key, d)
51 nt.assert_in(key, d)
52 # FIXME: always allow None, probably not a good idea
52 # FIXME: always allow None, probably not a good idea
53 if d[key] is None:
53 if d[key] is None:
54 continue
54 continue
55 try:
55 try:
56 setattr(self, key, d[key])
56 setattr(self, key, d[key])
57 except TraitError as e:
57 except TraitError as e:
58 assert False, str(e)
58 assert False, str(e)
59
59
60
60
61 class Version(Unicode):
61 class Version(Unicode):
62 def __init__(self, *args, **kwargs):
62 def __init__(self, *args, **kwargs):
63 self.min = kwargs.pop('min', None)
63 self.min = kwargs.pop('min', None)
64 self.max = kwargs.pop('max', None)
64 self.max = kwargs.pop('max', None)
65 kwargs['default_value'] = self.min
65 kwargs['default_value'] = self.min
66 super(Version, self).__init__(*args, **kwargs)
66 super(Version, self).__init__(*args, **kwargs)
67
67
68 def validate(self, obj, value):
68 def validate(self, obj, value):
69 if self.min and V(value) < V(self.min):
69 if self.min and V(value) < V(self.min):
70 raise TraitError("bad version: %s < %s" % (value, self.min))
70 raise TraitError("bad version: %s < %s" % (value, self.min))
71 if self.max and (V(value) > V(self.max)):
71 if self.max and (V(value) > V(self.max)):
72 raise TraitError("bad version: %s > %s" % (value, self.max))
72 raise TraitError("bad version: %s > %s" % (value, self.max))
73
73
74
74
75 class RMessage(Reference):
75 class RMessage(Reference):
76 msg_id = Unicode()
76 msg_id = Unicode()
77 msg_type = Unicode()
77 msg_type = Unicode()
78 header = Dict()
78 header = Dict()
79 parent_header = Dict()
79 parent_header = Dict()
80 content = Dict()
80 content = Dict()
81
81
82 def check(self, d):
82 def check(self, d):
83 super(RMessage, self).check(d)
83 super(RMessage, self).check(d)
84 RHeader().check(self.header)
84 RHeader().check(self.header)
85 if self.parent_header:
85 if self.parent_header:
86 RHeader().check(self.parent_header)
86 RHeader().check(self.parent_header)
87
87
88 class RHeader(Reference):
88 class RHeader(Reference):
89 msg_id = Unicode()
89 msg_id = Unicode()
90 msg_type = Unicode()
90 msg_type = Unicode()
91 session = Unicode()
91 session = Unicode()
92 username = Unicode()
92 username = Unicode()
93 version = Version(min='5.0')
93 version = Version(min='5.0')
94
94
95 mime_pat = re.compile(r'^[\w\-\+\.]+/[\w\-\+\.]+$')
95 mime_pat = re.compile(r'^[\w\-\+\.]+/[\w\-\+\.]+$')
96
96
97 class MimeBundle(Reference):
97 class MimeBundle(Reference):
98 metadata = Dict()
98 metadata = Dict()
99 data = Dict()
99 data = Dict()
100 def _data_changed(self, name, old, new):
100 def _data_changed(self, name, old, new):
101 for k,v in iteritems(new):
101 for k,v in iteritems(new):
102 assert mime_pat.match(k)
102 assert mime_pat.match(k)
103 nt.assert_is_instance(v, string_types)
103 nt.assert_is_instance(v, string_types)
104
104
105 # shell replies
105 # shell replies
106
106
107 class ExecuteReply(Reference):
107 class ExecuteReply(Reference):
108 execution_count = Integer()
108 execution_count = Integer()
109 status = Enum((u'ok', u'error'))
109 status = Enum((u'ok', u'error'))
110
110
111 def check(self, d):
111 def check(self, d):
112 Reference.check(self, d)
112 Reference.check(self, d)
113 if d['status'] == 'ok':
113 if d['status'] == 'ok':
114 ExecuteReplyOkay().check(d)
114 ExecuteReplyOkay().check(d)
115 elif d['status'] == 'error':
115 elif d['status'] == 'error':
116 ExecuteReplyError().check(d)
116 ExecuteReplyError().check(d)
117
117
118
118
119 class ExecuteReplyOkay(Reference):
119 class ExecuteReplyOkay(Reference):
120 payload = List(Dict)
120 payload = List(Dict)
121 user_expressions = Dict()
121 user_expressions = Dict()
122
122
123
123
124 class ExecuteReplyError(Reference):
124 class ExecuteReplyError(Reference):
125 ename = Unicode()
125 ename = Unicode()
126 evalue = Unicode()
126 evalue = Unicode()
127 traceback = List(Unicode)
127 traceback = List(Unicode)
128
128
129
129
130 class InspectReply(MimeBundle):
130 class InspectReply(MimeBundle):
131 found = Bool()
131 found = Bool()
132
132
133
133
134 class ArgSpec(Reference):
134 class ArgSpec(Reference):
135 args = List(Unicode)
135 args = List(Unicode)
136 varargs = Unicode()
136 varargs = Unicode()
137 varkw = Unicode()
137 varkw = Unicode()
138 defaults = List()
138 defaults = List()
139
139
140
140
141 class Status(Reference):
141 class Status(Reference):
142 execution_state = Enum((u'busy', u'idle', u'starting'))
142 execution_state = Enum((u'busy', u'idle', u'starting'))
143
143
144
144
145 class CompleteReply(Reference):
145 class CompleteReply(Reference):
146 matches = List(Unicode)
146 matches = List(Unicode)
147 cursor_start = Integer()
147 cursor_start = Integer()
148 cursor_end = Integer()
148 cursor_end = Integer()
149 status = Unicode()
149 status = Unicode()
150
150
151 class LanguageInfo(Reference):
151 class LanguageInfo(Reference):
152 name = Unicode('python')
152 name = Unicode('python')
153 version = Unicode(sys.version.split()[0])
153 version = Unicode(sys.version.split()[0])
154
154
155 class KernelInfoReply(Reference):
155 class KernelInfoReply(Reference):
156 protocol_version = Version(min='5.0')
156 protocol_version = Version(min='5.0')
157 implementation = Unicode('ipython')
157 implementation = Unicode('ipython')
158 implementation_version = Version(min='2.1')
158 implementation_version = Version(min='2.1')
159 language_info = Dict()
159 language_info = Dict()
160 banner = Unicode()
160 banner = Unicode()
161
161
162 def check(self, d):
162 def check(self, d):
163 Reference.check(self, d)
163 Reference.check(self, d)
164 LanguageInfo().check(d['language_info'])
164 LanguageInfo().check(d['language_info'])
165
165
166
166
167 class IsCompleteReply(Reference):
167 class IsCompleteReply(Reference):
168 status = Enum((u'complete', u'incomplete', u'invalid', u'unknown'))
168 status = Enum((u'complete', u'incomplete', u'invalid', u'unknown'))
169
169
170 def check(self, d):
170 def check(self, d):
171 Reference.check(self, d)
171 Reference.check(self, d)
172 if d['status'] == 'incomplete':
172 if d['status'] == 'incomplete':
173 IsCompleteReplyIncomplete().check(d)
173 IsCompleteReplyIncomplete().check(d)
174
174
175 class IsCompleteReplyIncomplete(Reference):
175 class IsCompleteReplyIncomplete(Reference):
176 indent = Unicode()
176 indent = Unicode()
177
177
178
178
179 # IOPub messages
179 # IOPub messages
180
180
181 class ExecuteInput(Reference):
181 class ExecuteInput(Reference):
182 code = Unicode()
182 code = Unicode()
183 execution_count = Integer()
183 execution_count = Integer()
184
184
185
185
186 Error = ExecuteReplyError
186 Error = ExecuteReplyError
187
187
188
188
189 class Stream(Reference):
189 class Stream(Reference):
190 name = Enum((u'stdout', u'stderr'))
190 name = Enum((u'stdout', u'stderr'))
191 text = Unicode()
191 text = Unicode()
192
192
193
193
194 class DisplayData(MimeBundle):
194 class DisplayData(MimeBundle):
195 pass
195 pass
196
196
197
197
198 class ExecuteResult(MimeBundle):
198 class ExecuteResult(MimeBundle):
199 execution_count = Integer()
199 execution_count = Integer()
200
200
201 class HistoryReply(MimeBundle):
201 class HistoryReply(Reference):
202 history = List(Unicode)
202 history = List(Unicode)
203
203
204
204
205 references = {
205 references = {
206 'execute_reply' : ExecuteReply(),
206 'execute_reply' : ExecuteReply(),
207 'inspect_reply' : InspectReply(),
207 'inspect_reply' : InspectReply(),
208 'status' : Status(),
208 'status' : Status(),
209 'complete_reply' : CompleteReply(),
209 'complete_reply' : CompleteReply(),
210 'kernel_info_reply': KernelInfoReply(),
210 'kernel_info_reply': KernelInfoReply(),
211 'is_complete_reply': IsCompleteReply(),
211 'is_complete_reply': IsCompleteReply(),
212 'execute_input' : ExecuteInput(),
212 'execute_input' : ExecuteInput(),
213 'execute_result' : ExecuteResult(),
213 'execute_result' : ExecuteResult(),
214 'history_reply' : HistoryReply(),
214 'history_reply' : HistoryReply(),
215 'error' : Error(),
215 'error' : Error(),
216 'stream' : Stream(),
216 'stream' : Stream(),
217 'display_data' : DisplayData(),
217 'display_data' : DisplayData(),
218 'header' : RHeader(),
218 'header' : RHeader(),
219 }
219 }
220 """
220 """
221 Specifications of `content` part of the reply messages.
221 Specifications of `content` part of the reply messages.
222 """
222 """
223
223
224
224
225 def validate_message(msg, msg_type=None, parent=None):
225 def validate_message(msg, msg_type=None, parent=None):
226 """validate a message
226 """validate a message
227
227
228 This is a generator, and must be iterated through to actually
228 This is a generator, and must be iterated through to actually
229 trigger each test.
229 trigger each test.
230
230
231 If msg_type and/or parent are given, the msg_type and/or parent msg_id
231 If msg_type and/or parent are given, the msg_type and/or parent msg_id
232 are compared with the given values.
232 are compared with the given values.
233 """
233 """
234 RMessage().check(msg)
234 RMessage().check(msg)
235 if msg_type:
235 if msg_type:
236 nt.assert_equal(msg['msg_type'], msg_type)
236 nt.assert_equal(msg['msg_type'], msg_type)
237 if parent:
237 if parent:
238 nt.assert_equal(msg['parent_header']['msg_id'], parent)
238 nt.assert_equal(msg['parent_header']['msg_id'], parent)
239 content = msg['content']
239 content = msg['content']
240 ref = references[msg['msg_type']]
240 ref = references[msg['msg_type']]
241 ref.check(content)
241 ref.check(content)
242
242
243
243
244 #-----------------------------------------------------------------------------
244 #-----------------------------------------------------------------------------
245 # Tests
245 # Tests
246 #-----------------------------------------------------------------------------
246 #-----------------------------------------------------------------------------
247
247
248 # Shell channel
248 # Shell channel
249
249
250 def test_execute():
250 def test_execute():
251 flush_channels()
251 flush_channels()
252
252
253 msg_id = KC.execute(code='x=1')
253 msg_id = KC.execute(code='x=1')
254 reply = KC.get_shell_msg(timeout=TIMEOUT)
254 reply = KC.get_shell_msg(timeout=TIMEOUT)
255 validate_message(reply, 'execute_reply', msg_id)
255 validate_message(reply, 'execute_reply', msg_id)
256
256
257
257
258 def test_execute_silent():
258 def test_execute_silent():
259 flush_channels()
259 flush_channels()
260 msg_id, reply = execute(code='x=1', silent=True)
260 msg_id, reply = execute(code='x=1', silent=True)
261
261
262 # flush status=idle
262 # flush status=idle
263 status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
263 status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
264 validate_message(status, 'status', msg_id)
264 validate_message(status, 'status', msg_id)
265 nt.assert_equal(status['content']['execution_state'], 'idle')
265 nt.assert_equal(status['content']['execution_state'], 'idle')
266
266
267 nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
267 nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
268 count = reply['execution_count']
268 count = reply['execution_count']
269
269
270 msg_id, reply = execute(code='x=2', silent=True)
270 msg_id, reply = execute(code='x=2', silent=True)
271
271
272 # flush status=idle
272 # flush status=idle
273 status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
273 status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
274 validate_message(status, 'status', msg_id)
274 validate_message(status, 'status', msg_id)
275 nt.assert_equal(status['content']['execution_state'], 'idle')
275 nt.assert_equal(status['content']['execution_state'], 'idle')
276
276
277 nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
277 nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
278 count_2 = reply['execution_count']
278 count_2 = reply['execution_count']
279 nt.assert_equal(count_2, count)
279 nt.assert_equal(count_2, count)
280
280
281
281
282 def test_execute_error():
282 def test_execute_error():
283 flush_channels()
283 flush_channels()
284
284
285 msg_id, reply = execute(code='1/0')
285 msg_id, reply = execute(code='1/0')
286 nt.assert_equal(reply['status'], 'error')
286 nt.assert_equal(reply['status'], 'error')
287 nt.assert_equal(reply['ename'], 'ZeroDivisionError')
287 nt.assert_equal(reply['ename'], 'ZeroDivisionError')
288
288
289 error = KC.iopub_channel.get_msg(timeout=TIMEOUT)
289 error = KC.iopub_channel.get_msg(timeout=TIMEOUT)
290 validate_message(error, 'error', msg_id)
290 validate_message(error, 'error', msg_id)
291
291
292
292
293 def test_execute_inc():
293 def test_execute_inc():
294 """execute request should increment execution_count"""
294 """execute request should increment execution_count"""
295 flush_channels()
295 flush_channels()
296
296
297 msg_id, reply = execute(code='x=1')
297 msg_id, reply = execute(code='x=1')
298 count = reply['execution_count']
298 count = reply['execution_count']
299
299
300 flush_channels()
300 flush_channels()
301
301
302 msg_id, reply = execute(code='x=2')
302 msg_id, reply = execute(code='x=2')
303 count_2 = reply['execution_count']
303 count_2 = reply['execution_count']
304 nt.assert_equal(count_2, count+1)
304 nt.assert_equal(count_2, count+1)
305
305
306
306
307 def test_user_expressions():
307 def test_user_expressions():
308 flush_channels()
308 flush_channels()
309
309
310 msg_id, reply = execute(code='x=1', user_expressions=dict(foo='x+1'))
310 msg_id, reply = execute(code='x=1', user_expressions=dict(foo='x+1'))
311 user_expressions = reply['user_expressions']
311 user_expressions = reply['user_expressions']
312 nt.assert_equal(user_expressions, {u'foo': {
312 nt.assert_equal(user_expressions, {u'foo': {
313 u'status': u'ok',
313 u'status': u'ok',
314 u'data': {u'text/plain': u'2'},
314 u'data': {u'text/plain': u'2'},
315 u'metadata': {},
315 u'metadata': {},
316 }})
316 }})
317
317
318
318
319 def test_user_expressions_fail():
319 def test_user_expressions_fail():
320 flush_channels()
320 flush_channels()
321
321
322 msg_id, reply = execute(code='x=0', user_expressions=dict(foo='nosuchname'))
322 msg_id, reply = execute(code='x=0', user_expressions=dict(foo='nosuchname'))
323 user_expressions = reply['user_expressions']
323 user_expressions = reply['user_expressions']
324 foo = user_expressions['foo']
324 foo = user_expressions['foo']
325 nt.assert_equal(foo['status'], 'error')
325 nt.assert_equal(foo['status'], 'error')
326 nt.assert_equal(foo['ename'], 'NameError')
326 nt.assert_equal(foo['ename'], 'NameError')
327
327
328
328
329 def test_oinfo():
329 def test_oinfo():
330 flush_channels()
330 flush_channels()
331
331
332 msg_id = KC.inspect('a')
332 msg_id = KC.inspect('a')
333 reply = KC.get_shell_msg(timeout=TIMEOUT)
333 reply = KC.get_shell_msg(timeout=TIMEOUT)
334 validate_message(reply, 'inspect_reply', msg_id)
334 validate_message(reply, 'inspect_reply', msg_id)
335
335
336
336
337 def test_oinfo_found():
337 def test_oinfo_found():
338 flush_channels()
338 flush_channels()
339
339
340 msg_id, reply = execute(code='a=5')
340 msg_id, reply = execute(code='a=5')
341
341
342 msg_id = KC.inspect('a')
342 msg_id = KC.inspect('a')
343 reply = KC.get_shell_msg(timeout=TIMEOUT)
343 reply = KC.get_shell_msg(timeout=TIMEOUT)
344 validate_message(reply, 'inspect_reply', msg_id)
344 validate_message(reply, 'inspect_reply', msg_id)
345 content = reply['content']
345 content = reply['content']
346 assert content['found']
346 assert content['found']
347 text = content['data']['text/plain']
347 text = content['data']['text/plain']
348 nt.assert_in('Type:', text)
348 nt.assert_in('Type:', text)
349 nt.assert_in('Docstring:', text)
349 nt.assert_in('Docstring:', text)
350
350
351
351
352 def test_oinfo_detail():
352 def test_oinfo_detail():
353 flush_channels()
353 flush_channels()
354
354
355 msg_id, reply = execute(code='ip=get_ipython()')
355 msg_id, reply = execute(code='ip=get_ipython()')
356
356
357 msg_id = KC.inspect('ip.object_inspect', cursor_pos=10, detail_level=1)
357 msg_id = KC.inspect('ip.object_inspect', cursor_pos=10, detail_level=1)
358 reply = KC.get_shell_msg(timeout=TIMEOUT)
358 reply = KC.get_shell_msg(timeout=TIMEOUT)
359 validate_message(reply, 'inspect_reply', msg_id)
359 validate_message(reply, 'inspect_reply', msg_id)
360 content = reply['content']
360 content = reply['content']
361 assert content['found']
361 assert content['found']
362 text = content['data']['text/plain']
362 text = content['data']['text/plain']
363 nt.assert_in('Definition:', text)
363 nt.assert_in('Definition:', text)
364 nt.assert_in('Source:', text)
364 nt.assert_in('Source:', text)
365
365
366
366
367 def test_oinfo_not_found():
367 def test_oinfo_not_found():
368 flush_channels()
368 flush_channels()
369
369
370 msg_id = KC.inspect('dne')
370 msg_id = KC.inspect('dne')
371 reply = KC.get_shell_msg(timeout=TIMEOUT)
371 reply = KC.get_shell_msg(timeout=TIMEOUT)
372 validate_message(reply, 'inspect_reply', msg_id)
372 validate_message(reply, 'inspect_reply', msg_id)
373 content = reply['content']
373 content = reply['content']
374 nt.assert_false(content['found'])
374 nt.assert_false(content['found'])
375
375
376
376
377 def test_complete():
377 def test_complete():
378 flush_channels()
378 flush_channels()
379
379
380 msg_id, reply = execute(code="alpha = albert = 5")
380 msg_id, reply = execute(code="alpha = albert = 5")
381
381
382 msg_id = KC.complete('al', 2)
382 msg_id = KC.complete('al', 2)
383 reply = KC.get_shell_msg(timeout=TIMEOUT)
383 reply = KC.get_shell_msg(timeout=TIMEOUT)
384 validate_message(reply, 'complete_reply', msg_id)
384 validate_message(reply, 'complete_reply', msg_id)
385 matches = reply['content']['matches']
385 matches = reply['content']['matches']
386 for name in ('alpha', 'albert'):
386 for name in ('alpha', 'albert'):
387 nt.assert_in(name, matches)
387 nt.assert_in(name, matches)
388
388
389
389
390 def test_kernel_info_request():
390 def test_kernel_info_request():
391 flush_channels()
391 flush_channels()
392
392
393 msg_id = KC.kernel_info()
393 msg_id = KC.kernel_info()
394 reply = KC.get_shell_msg(timeout=TIMEOUT)
394 reply = KC.get_shell_msg(timeout=TIMEOUT)
395 validate_message(reply, 'kernel_info_reply', msg_id)
395 validate_message(reply, 'kernel_info_reply', msg_id)
396
396
397
397
398 def test_single_payload():
398 def test_single_payload():
399 flush_channels()
399 flush_channels()
400 msg_id, reply = execute(code="for i in range(3):\n"+
400 msg_id, reply = execute(code="for i in range(3):\n"+
401 " x=range?\n")
401 " x=range?\n")
402 payload = reply['payload']
402 payload = reply['payload']
403 next_input_pls = [pl for pl in payload if pl["source"] == "set_next_input"]
403 next_input_pls = [pl for pl in payload if pl["source"] == "set_next_input"]
404 nt.assert_equal(len(next_input_pls), 1)
404 nt.assert_equal(len(next_input_pls), 1)
405
405
406 def test_is_complete():
406 def test_is_complete():
407 flush_channels()
407 flush_channels()
408 a
409 msg_id = KC.is_complete("a = 1")
408 msg_id = KC.is_complete("a = 1")
410 reply = KC.get_shell_msg(timeout=TIMEOUT)
409 reply = KC.get_shell_msg(timeout=TIMEOUT)
411 validate_message(reply, 'is_complete_reply', msg_id)
410 validate_message(reply, 'is_complete_reply', msg_id)
412
411
413 def test_history():
412 def test_history_range():
414 flush_channels()
413 flush_channels()
415
414
416 msg_id = KC.history("range", True, True)
415 msg_id = KC.history("range", True, True)
417 reply = KC.get_shell_msg(timeout=TIMEOUT)
416 reply = KC.get_shell_msg(timeout=TIMEOUT)
418 validate_message(reply, 'history_reply', msg_id)
417 validate_message(reply, 'history_reply', msg_id)
419
418
419 def test_history_tail():
420 flush_channels()
421
422 msg_id = KC.history("tail", True, True, n = 1)
423 reply = KC.get_shell_msg(timeout=TIMEOUT)
424 validate_message(reply, 'history_reply', msg_id)
425
426 def test_history_search():
427 flush_channels()
428
429 msg_id = KC.history("search", True, True, n = 1, pattern = "*")
430 reply = KC.get_shell_msg(timeout=TIMEOUT)
431 validate_message(reply, 'history_reply', msg_id)
432
420 # IOPub channel
433 # IOPub channel
421
434
422
435
423 def test_stream():
436 def test_stream():
424 flush_channels()
437 flush_channels()
425
438
426 msg_id, reply = execute("print('hi')")
439 msg_id, reply = execute("print('hi')")
427
440
428 stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT)
441 stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT)
429 validate_message(stdout, 'stream', msg_id)
442 validate_message(stdout, 'stream', msg_id)
430 content = stdout['content']
443 content = stdout['content']
431 nt.assert_equal(content['text'], u'hi\n')
444 nt.assert_equal(content['text'], u'hi\n')
432
445
433
446
434 def test_display_data():
447 def test_display_data():
435 flush_channels()
448 flush_channels()
436
449
437 msg_id, reply = execute("from IPython.core.display import display; display(1)")
450 msg_id, reply = execute("from IPython.core.display import display; display(1)")
438
451
439 display = KC.iopub_channel.get_msg(timeout=TIMEOUT)
452 display = KC.iopub_channel.get_msg(timeout=TIMEOUT)
440 validate_message(display, 'display_data', parent=msg_id)
453 validate_message(display, 'display_data', parent=msg_id)
441 data = display['content']['data']
454 data = display['content']['data']
442 nt.assert_equal(data['text/plain'], u'1')
455 nt.assert_equal(data['text/plain'], u'1')
443
456
General Comments 0
You need to be logged in to leave comments. Login now