Show More
@@ -6,12 +6,11 b'' | |||
|
6 | 6 | # The full license is in the file COPYING.txt, distributed with this software. |
|
7 | 7 | #----------------------------------------------------------------------------- |
|
8 | 8 | |
|
9 |
from nose.tools import assert_equal |
|
|
9 | from nose.tools import assert_equal | |
|
10 | 10 | |
|
11 | 11 | from IPython.external import argparse |
|
12 | 12 | from IPython.core.magic_arguments import (argument, argument_group, kwds, |
|
13 | 13 | magic_arguments, parse_argstring, real_name) |
|
14 | from IPython.testing.decorators import parametric | |
|
15 | 14 | |
|
16 | 15 | |
|
17 | 16 | @magic_arguments() |
@@ -74,48 +73,46 b' def foo(self, args):' | |||
|
74 | 73 | return parse_argstring(foo, args) |
|
75 | 74 | |
|
76 | 75 | |
|
77 | @parametric | |
|
78 | 76 | def test_magic_arguments(): |
|
79 | # Ideally, these would be doctests, but I could not get it to work. | |
|
80 | yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
81 | yield assert_equal(getattr(magic_foo1, 'argcmd_name', None), None) | |
|
82 | yield assert_equal(real_name(magic_foo1), 'foo1') | |
|
83 | yield assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None)) | |
|
84 | yield assert_true(hasattr(magic_foo1, 'has_arguments')) | |
|
85 | ||
|
86 | yield assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n') | |
|
87 | yield assert_equal(getattr(magic_foo2, 'argcmd_name', None), None) | |
|
88 | yield assert_equal(real_name(magic_foo2), 'foo2') | |
|
89 | yield assert_equal(magic_foo2(None, ''), argparse.Namespace()) | |
|
90 | yield assert_true(hasattr(magic_foo2, 'has_arguments')) | |
|
91 | ||
|
92 | yield assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n') | |
|
93 | yield assert_equal(getattr(magic_foo3, 'argcmd_name', None), None) | |
|
94 |
|
|
|
95 | yield assert_equal(magic_foo3(None, ''), | |
|
77 | assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
78 | assert_equal(getattr(magic_foo1, 'argcmd_name', None), None) | |
|
79 | assert_equal(real_name(magic_foo1), 'foo1') | |
|
80 | assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None)) | |
|
81 | assert hasattr(magic_foo1, 'has_arguments') | |
|
82 | ||
|
83 | assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n') | |
|
84 | assert_equal(getattr(magic_foo2, 'argcmd_name', None), None) | |
|
85 | assert_equal(real_name(magic_foo2), 'foo2') | |
|
86 | assert_equal(magic_foo2(None, ''), argparse.Namespace()) | |
|
87 | assert hasattr(magic_foo2, 'has_arguments') | |
|
88 | ||
|
89 | assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n') | |
|
90 | assert_equal(getattr(magic_foo3, 'argcmd_name', None), None) | |
|
91 | assert_equal(real_name(magic_foo3), 'foo3') | |
|
92 | assert_equal(magic_foo3(None, ''), | |
|
96 | 93 | argparse.Namespace(bar=None, baz=None, foo=None)) |
|
97 |
|
|
|
98 | ||
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 | ||
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 | ||
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 | ||
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
94 | assert hasattr(magic_foo3, 'has_arguments') | |
|
95 | ||
|
96 | assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
97 | assert_equal(getattr(magic_foo4, 'argcmd_name', None), None) | |
|
98 | assert_equal(real_name(magic_foo4), 'foo4') | |
|
99 | assert_equal(magic_foo4(None, ''), argparse.Namespace()) | |
|
100 | assert hasattr(magic_foo4, 'has_arguments') | |
|
101 | ||
|
102 | assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
103 | assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate') | |
|
104 | assert_equal(real_name(magic_foo5), 'frobnicate') | |
|
105 | assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None)) | |
|
106 | assert hasattr(magic_foo5, 'has_arguments') | |
|
107 | ||
|
108 | assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
109 | assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None) | |
|
110 | assert_equal(real_name(magic_magic_foo), 'magic_foo') | |
|
111 | assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None)) | |
|
112 | assert hasattr(magic_magic_foo, 'has_arguments') | |
|
113 | ||
|
114 | assert_equal(foo.__doc__, '%foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
115 | assert_equal(getattr(foo, 'argcmd_name', None), None) | |
|
116 | assert_equal(real_name(foo), 'foo') | |
|
117 | assert_equal(foo(None, ''), argparse.Namespace(foo=None)) | |
|
118 | assert hasattr(foo, 'has_arguments') |
@@ -14,7 +14,6 b' from IPython.testing.globalipapp import get_ipython' | |||
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | ip = get_ipython() |
|
16 | 16 | |
|
17 | @dec.parametric | |
|
18 | 17 | def test_prefilter(): |
|
19 | 18 | """Test user input conversions""" |
|
20 | 19 | |
@@ -23,19 +22,18 b' def test_prefilter():' | |||
|
23 | 22 | ] |
|
24 | 23 | |
|
25 | 24 | for raw, correct in pairs: |
|
26 |
|
|
|
25 | nt.assert_equal(ip.prefilter(raw), correct) | |
|
27 | 26 | |
|
28 | 27 | |
|
29 | @dec.parametric | |
|
30 | 28 | def test_autocall_binops(): |
|
31 | 29 | """See https://github.com/ipython/ipython/issues/81""" |
|
32 | 30 | ip.magic('autocall 2') |
|
33 | 31 | f = lambda x: x |
|
34 | 32 | ip.user_ns['f'] = f |
|
35 | 33 | try: |
|
36 |
|
|
|
34 | nt.assert_equal(ip.prefilter('f 1'),'f(1)') | |
|
37 | 35 | for t in ['f +1', 'f -1']: |
|
38 |
|
|
|
36 | nt.assert_equal(ip.prefilter(t), t) | |
|
39 | 37 | |
|
40 | 38 | # Run tests again with a more permissive exclude_regexp, which will |
|
41 | 39 | # allow transformation of binary operations ('f -1' -> 'f(-1)'). |
@@ -47,8 +45,8 b' def test_autocall_binops():' | |||
|
47 | 45 | ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or ' |
|
48 | 46 | pm.sort_checkers() |
|
49 | 47 | |
|
50 |
|
|
|
51 |
|
|
|
48 | nt.assert_equal(ip.prefilter('f -1'), 'f(-1)') | |
|
49 | nt.assert_equal(ip.prefilter('f +1'), 'f(+1)') | |
|
52 | 50 | finally: |
|
53 | 51 | pm.unregister_checker(ac) |
|
54 | 52 | finally: |
@@ -56,7 +54,6 b' def test_autocall_binops():' | |||
|
56 | 54 | del ip.user_ns['f'] |
|
57 | 55 | |
|
58 | 56 | |
|
59 | @dec.parametric | |
|
60 | 57 | def test_issue_114(): |
|
61 | 58 | """Check that multiline string literals don't expand as magic |
|
62 | 59 | see http://github.com/ipython/ipython/issues/114""" |
@@ -70,7 +67,7 b' def test_issue_114():' | |||
|
70 | 67 | try: |
|
71 | 68 | for mgk in ip.magics_manager.lsmagic()['line']: |
|
72 | 69 | raw = template % mgk |
|
73 |
|
|
|
70 | nt.assert_equal(ip.prefilter(raw), raw) | |
|
74 | 71 | finally: |
|
75 | 72 | ip.prefilter_manager.multi_line_specials = msp |
|
76 | 73 |
@@ -24,7 +24,6 b' import numpy as np' | |||
|
24 | 24 | |
|
25 | 25 | # Our own imports |
|
26 | 26 | from IPython.core.interactiveshell import InteractiveShell |
|
27 | from IPython.testing import decorators as dec | |
|
28 | 27 | from .. import pylabtools as pt |
|
29 | 28 | |
|
30 | 29 | #----------------------------------------------------------------------------- |
@@ -39,11 +38,10 b' from .. import pylabtools as pt' | |||
|
39 | 38 | # Classes and functions |
|
40 | 39 | #----------------------------------------------------------------------------- |
|
41 | 40 | |
|
42 | @dec.parametric | |
|
43 | 41 | def test_figure_to_svg(): |
|
44 | 42 | # simple empty-figure test |
|
45 | 43 | fig = plt.figure() |
|
46 |
|
|
|
44 | nt.assert_equal(pt.print_figure(fig, 'svg'), None) | |
|
47 | 45 | |
|
48 | 46 | plt.close('all') |
|
49 | 47 | |
@@ -53,7 +51,7 b' def test_figure_to_svg():' | |||
|
53 | 51 | ax.plot([1,2,3]) |
|
54 | 52 | plt.draw() |
|
55 | 53 | svg = pt.print_figure(fig, 'svg')[:100].lower() |
|
56 |
|
|
|
54 | nt.assert_in('doctype svg', svg) | |
|
57 | 55 | |
|
58 | 56 | |
|
59 | 57 | def test_import_pylab(): |
@@ -27,7 +27,6 b' from IPython.kernel.launcher import swallow_argv' | |||
|
27 | 27 | # Classes and functions |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | |
|
30 | @dec.parametric | |
|
31 | 30 | def test_swallow_argv(): |
|
32 | 31 | tests = [ |
|
33 | 32 | # expected , argv , aliases, flags |
@@ -56,5 +55,5 b' def test_swallow_argv():' | |||
|
56 | 55 | "expected : %r" % expected, |
|
57 | 56 | "returned : %r" % stripped, |
|
58 | 57 | ]) |
|
59 |
|
|
|
58 | nt.assert_equal(expected, stripped, message) | |
|
60 | 59 |
@@ -15,7 +15,6 b' import nose.tools as nt' | |||
|
15 | 15 | |
|
16 | 16 | from IPython.kernel import KernelManager |
|
17 | 17 | |
|
18 | from IPython.testing import decorators as dec | |
|
19 | 18 | from IPython.utils.traitlets import ( |
|
20 | 19 | HasTraits, TraitError, Bool, Unicode, Dict, Integer, List, Enum, Any, |
|
21 | 20 | ) |
@@ -101,14 +100,14 b' class Reference(HasTraits):' | |||
|
101 | 100 | def check(self, d): |
|
102 | 101 | """validate a dict against our traits""" |
|
103 | 102 | for key in self.trait_names(): |
|
104 | yield nt.assert_true(key in d, "Missing key: %r, should be found in %s" % (key, d)) | |
|
103 | nt.assert_in(key, d) | |
|
105 | 104 | # FIXME: always allow None, probably not a good idea |
|
106 | 105 | if d[key] is None: |
|
107 | 106 | continue |
|
108 | 107 | try: |
|
109 | 108 | setattr(self, key, d[key]) |
|
110 | 109 | except TraitError as e: |
|
111 |
|
|
|
110 | nt.assert_true(False, str(e)) | |
|
112 | 111 | |
|
113 | 112 | |
|
114 | 113 | class RMessage(Reference): |
@@ -133,14 +132,11 b' class ExecuteReply(Reference):' | |||
|
133 | 132 | status = Enum((u'ok', u'error')) |
|
134 | 133 | |
|
135 | 134 | def check(self, d): |
|
136 |
|
|
|
137 | yield tst | |
|
135 | Reference.check(self, d) | |
|
138 | 136 | if d['status'] == 'ok': |
|
139 |
|
|
|
140 | yield tst | |
|
137 | ExecuteReplyOkay().check(d) | |
|
141 | 138 | elif d['status'] == 'error': |
|
142 |
|
|
|
143 | yield tst | |
|
139 | ExecuteReplyError().check(d) | |
|
144 | 140 | |
|
145 | 141 | |
|
146 | 142 | class ExecuteReplyOkay(Reference): |
@@ -177,11 +173,9 b' class OInfoReply(Reference):' | |||
|
177 | 173 | source = Unicode() |
|
178 | 174 | |
|
179 | 175 | def check(self, d): |
|
180 |
|
|
|
181 | yield tst | |
|
176 | Reference.check(self, d) | |
|
182 | 177 | if d['argspec'] is not None: |
|
183 |
|
|
|
184 | yield tst | |
|
178 | ArgSpec().check(d['argspec']) | |
|
185 | 179 | |
|
186 | 180 | |
|
187 | 181 | class ArgSpec(Reference): |
@@ -212,10 +206,8 b' class KernelInfoReply(Reference):' | |||
|
212 | 206 | |
|
213 | 207 | def _ipython_version_changed(self, name, old, new): |
|
214 | 208 | for v in new: |
|
215 | nt.assert_true( | |
|
216 | isinstance(v, int) or isinstance(v, basestring), | |
|
217 | 'expected int or string as version component, got {0!r}' | |
|
218 | .format(v)) | |
|
209 | assert isinstance(v, int) or isinstance(v, basestring), \ | |
|
210 | 'expected int or string as version component, got {0!r}'.format(v) | |
|
219 | 211 | |
|
220 | 212 | |
|
221 | 213 | # IOPub messages |
@@ -241,8 +233,8 b' class DisplayData(Reference):' | |||
|
241 | 233 | data = Dict() |
|
242 | 234 | def _data_changed(self, name, old, new): |
|
243 | 235 | for k,v in new.iteritems(): |
|
244 |
|
|
|
245 |
nt.assert_ |
|
|
236 | assert mime_pat.match(k) | |
|
237 | nt.assert_is_instance(v, basestring) | |
|
246 | 238 | |
|
247 | 239 | |
|
248 | 240 | class PyOut(Reference): |
@@ -250,8 +242,8 b' class PyOut(Reference):' | |||
|
250 | 242 | data = Dict() |
|
251 | 243 | def _data_changed(self, name, old, new): |
|
252 | 244 | for k,v in new.iteritems(): |
|
253 |
|
|
|
254 |
nt.assert_ |
|
|
245 | assert mime_pat.match(k) | |
|
246 | nt.assert_is_instance(v, basestring) | |
|
255 | 247 | |
|
256 | 248 | |
|
257 | 249 | references = { |
@@ -282,13 +274,12 b' def validate_message(msg, msg_type=None, parent=None):' | |||
|
282 | 274 | """ |
|
283 | 275 | RMessage().check(msg) |
|
284 | 276 | if msg_type: |
|
285 |
|
|
|
277 | nt.assert_equal(msg['msg_type'], msg_type) | |
|
286 | 278 | if parent: |
|
287 |
|
|
|
279 | nt.assert_equal(msg['parent_header']['msg_id'], parent) | |
|
288 | 280 | content = msg['content'] |
|
289 | 281 | ref = references[msg['msg_type']] |
|
290 |
|
|
|
291 | yield tst | |
|
282 | ref.check(content) | |
|
292 | 283 | |
|
293 | 284 | |
|
294 | 285 | #----------------------------------------------------------------------------- |
@@ -297,54 +288,47 b' def validate_message(msg, msg_type=None, parent=None):' | |||
|
297 | 288 | |
|
298 | 289 | # Shell channel |
|
299 | 290 | |
|
300 | @dec.parametric | |
|
301 | 291 | def test_execute(): |
|
302 | 292 | flush_channels() |
|
303 | 293 | |
|
304 | 294 | msg_id = KC.execute(code='x=1') |
|
305 | 295 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
306 |
|
|
|
307 | yield tst | |
|
296 | validate_message(reply, 'execute_reply', msg_id) | |
|
308 | 297 | |
|
309 | 298 | |
|
310 | @dec.parametric | |
|
311 | 299 | def test_execute_silent(): |
|
312 | 300 | flush_channels() |
|
313 | 301 | msg_id, reply = execute(code='x=1', silent=True) |
|
314 | 302 | |
|
315 | 303 | # flush status=idle |
|
316 | 304 | status = KC.iopub_channel.get_msg(timeout=TIMEOUT) |
|
317 |
|
|
|
318 | yield tst | |
|
305 | validate_message(status, 'status', msg_id) | |
|
319 | 306 | nt.assert_equal(status['content']['execution_state'], 'idle') |
|
320 | 307 | |
|
321 |
|
|
|
308 | nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) | |
|
322 | 309 | count = reply['execution_count'] |
|
323 | 310 | |
|
324 | 311 | msg_id, reply = execute(code='x=2', silent=True) |
|
325 | 312 | |
|
326 | 313 | # flush status=idle |
|
327 | 314 | status = KC.iopub_channel.get_msg(timeout=TIMEOUT) |
|
328 |
|
|
|
329 | yield tst | |
|
330 | yield nt.assert_equal(status['content']['execution_state'], 'idle') | |
|
315 | validate_message(status, 'status', msg_id) | |
|
316 | nt.assert_equal(status['content']['execution_state'], 'idle') | |
|
331 | 317 | |
|
332 |
|
|
|
318 | nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1) | |
|
333 | 319 | count_2 = reply['execution_count'] |
|
334 |
|
|
|
320 | nt.assert_equal(count_2, count) | |
|
335 | 321 | |
|
336 | 322 | |
|
337 | @dec.parametric | |
|
338 | 323 | def test_execute_error(): |
|
339 | 324 | flush_channels() |
|
340 | 325 | |
|
341 | 326 | msg_id, reply = execute(code='1/0') |
|
342 |
|
|
|
343 |
|
|
|
327 | nt.assert_equal(reply['status'], 'error') | |
|
328 | nt.assert_equal(reply['ename'], 'ZeroDivisionError') | |
|
344 | 329 | |
|
345 | 330 | pyerr = KC.iopub_channel.get_msg(timeout=TIMEOUT) |
|
346 |
|
|
|
347 | yield tst | |
|
331 | validate_message(pyerr, 'pyerr', msg_id) | |
|
348 | 332 | |
|
349 | 333 | |
|
350 | 334 | def test_execute_inc(): |
@@ -405,17 +389,14 b' def test_user_expressions_fail():' | |||
|
405 | 389 | nt.assert_equal(foo['ename'], 'NameError') |
|
406 | 390 | |
|
407 | 391 | |
|
408 | @dec.parametric | |
|
409 | 392 | def test_oinfo(): |
|
410 | 393 | flush_channels() |
|
411 | 394 | |
|
412 | 395 | msg_id = KC.object_info('a') |
|
413 | 396 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
414 |
|
|
|
415 | yield tst | |
|
397 | validate_message(reply, 'object_info_reply', msg_id) | |
|
416 | 398 | |
|
417 | 399 | |
|
418 | @dec.parametric | |
|
419 | 400 | def test_oinfo_found(): |
|
420 | 401 | flush_channels() |
|
421 | 402 | |
@@ -423,15 +404,13 b' def test_oinfo_found():' | |||
|
423 | 404 | |
|
424 | 405 | msg_id = KC.object_info('a') |
|
425 | 406 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
426 |
|
|
|
427 | yield tst | |
|
407 | validate_message(reply, 'object_info_reply', msg_id) | |
|
428 | 408 | content = reply['content'] |
|
429 |
|
|
|
409 | assert content['found'] | |
|
430 | 410 | argspec = content['argspec'] |
|
431 | yield nt.assert_true(argspec is None, "didn't expect argspec dict, got %r" % argspec) | |
|
411 | nt.assert_is(argspec, None) | |
|
432 | 412 | |
|
433 | 413 | |
|
434 | @dec.parametric | |
|
435 | 414 | def test_oinfo_detail(): |
|
436 | 415 | flush_channels() |
|
437 | 416 | |
@@ -439,28 +418,24 b' def test_oinfo_detail():' | |||
|
439 | 418 | |
|
440 | 419 | msg_id = KC.object_info('ip.object_inspect', detail_level=2) |
|
441 | 420 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
442 |
|
|
|
443 | yield tst | |
|
421 | validate_message(reply, 'object_info_reply', msg_id) | |
|
444 | 422 | content = reply['content'] |
|
445 |
|
|
|
423 | assert content['found'] | |
|
446 | 424 | argspec = content['argspec'] |
|
447 |
|
|
|
448 |
|
|
|
425 | nt.assert_is_instance(argspec, dict, "expected non-empty argspec dict, got %r" % argspec) | |
|
426 | nt.assert_equal(argspec['defaults'], [0]) | |
|
449 | 427 | |
|
450 | 428 | |
|
451 | @dec.parametric | |
|
452 | 429 | def test_oinfo_not_found(): |
|
453 | 430 | flush_channels() |
|
454 | 431 | |
|
455 | 432 | msg_id = KC.object_info('dne') |
|
456 | 433 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
457 |
|
|
|
458 | yield tst | |
|
434 | validate_message(reply, 'object_info_reply', msg_id) | |
|
459 | 435 | content = reply['content'] |
|
460 |
|
|
|
436 | nt.assert_false(content['found']) | |
|
461 | 437 | |
|
462 | 438 | |
|
463 | @dec.parametric | |
|
464 | 439 | def test_complete(): |
|
465 | 440 | flush_channels() |
|
466 | 441 | |
@@ -468,49 +443,42 b' def test_complete():' | |||
|
468 | 443 | |
|
469 | 444 | msg_id = KC.complete('al', 'al', 2) |
|
470 | 445 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
471 |
|
|
|
472 | yield tst | |
|
446 | validate_message(reply, 'complete_reply', msg_id) | |
|
473 | 447 | matches = reply['content']['matches'] |
|
474 | 448 | for name in ('alpha', 'albert'): |
|
475 | yield nt.assert_true(name in matches, "Missing match: %r" % name) | |
|
449 | nt.assert_in(name, matches) | |
|
476 | 450 | |
|
477 | 451 | |
|
478 | @dec.parametric | |
|
479 | 452 | def test_kernel_info_request(): |
|
480 | 453 | flush_channels() |
|
481 | 454 | |
|
482 | 455 | msg_id = KC.kernel_info() |
|
483 | 456 | reply = KC.get_shell_msg(timeout=TIMEOUT) |
|
484 |
|
|
|
485 | yield tst | |
|
457 | validate_message(reply, 'kernel_info_reply', msg_id) | |
|
486 | 458 | |
|
487 | 459 | |
|
488 | 460 | # IOPub channel |
|
489 | 461 | |
|
490 | 462 | |
|
491 | @dec.parametric | |
|
492 | 463 | def test_stream(): |
|
493 | 464 | flush_channels() |
|
494 | 465 | |
|
495 | 466 | msg_id, reply = execute("print('hi')") |
|
496 | 467 | |
|
497 | 468 | stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT) |
|
498 |
|
|
|
499 | yield tst | |
|
469 | validate_message(stdout, 'stream', msg_id) | |
|
500 | 470 | content = stdout['content'] |
|
501 |
|
|
|
502 |
|
|
|
471 | nt.assert_equal(content['name'], u'stdout') | |
|
472 | nt.assert_equal(content['data'], u'hi\n') | |
|
503 | 473 | |
|
504 | 474 | |
|
505 | @dec.parametric | |
|
506 | 475 | def test_display_data(): |
|
507 | 476 | flush_channels() |
|
508 | 477 | |
|
509 | 478 | msg_id, reply = execute("from IPython.core.display import display; display(1)") |
|
510 | 479 | |
|
511 | 480 | display = KC.iopub_channel.get_msg(timeout=TIMEOUT) |
|
512 |
|
|
|
513 | yield tst | |
|
481 | validate_message(display, 'display_data', parent=msg_id) | |
|
514 | 482 | data = display['content']['data'] |
|
515 |
|
|
|
483 | nt.assert_equal(data['text/plain'], u'1') | |
|
516 | 484 |
@@ -14,8 +14,6 b' Authors' | |||
|
14 | 14 | |
|
15 | 15 | import nose.tools as nt |
|
16 | 16 | |
|
17 | from IPython.testing import decorators as dec | |
|
18 | ||
|
19 | 17 | from IPython.kernel import launcher, connect |
|
20 | 18 | from IPython import kernel |
|
21 | 19 | |
@@ -23,25 +21,21 b' from IPython import kernel' | |||
|
23 | 21 | # Classes and functions |
|
24 | 22 | #----------------------------------------------------------------------------- |
|
25 | 23 | |
|
26 | @dec.parametric | |
|
27 | 24 | def test_kms(): |
|
28 | 25 | for base in ("", "Multi"): |
|
29 | 26 | KM = base + "KernelManager" |
|
30 |
|
|
|
27 | nt.assert_in(KM, dir(kernel)) | |
|
31 | 28 | |
|
32 | @dec.parametric | |
|
33 | 29 | def test_kcs(): |
|
34 | 30 | for base in ("", "Blocking"): |
|
35 | 31 | KM = base + "KernelClient" |
|
36 |
|
|
|
32 | nt.assert_in(KM, dir(kernel)) | |
|
37 | 33 | |
|
38 | @dec.parametric | |
|
39 | 34 | def test_launcher(): |
|
40 | 35 | for name in launcher.__all__: |
|
41 |
|
|
|
36 | nt.assert_in(name, dir(kernel)) | |
|
42 | 37 | |
|
43 | @dec.parametric | |
|
44 | 38 | def test_connect(): |
|
45 | 39 | for name in connect.__all__: |
|
46 |
|
|
|
40 | nt.assert_in(name, dir(kernel)) | |
|
47 | 41 |
@@ -46,7 +46,6 b" DTYPES = ('uint8', 'float64', 'int32', [('g', 'float32')], '|S10')" | |||
|
46 | 46 | # Tests |
|
47 | 47 | #------------------------------------------------------------------------------- |
|
48 | 48 | |
|
49 | @dec.parametric | |
|
50 | 49 | def test_roundtrip_simple(): |
|
51 | 50 | for obj in [ |
|
52 | 51 | 'hello', |
@@ -55,18 +54,16 b' def test_roundtrip_simple():' | |||
|
55 | 54 | (b'123', 'hello'), |
|
56 | 55 | ]: |
|
57 | 56 | obj2 = roundtrip(obj) |
|
58 |
|
|
|
57 | nt.assert_equal(obj, obj2) | |
|
59 | 58 | |
|
60 | @dec.parametric | |
|
61 | 59 | def test_roundtrip_nested(): |
|
62 | 60 | for obj in [ |
|
63 | 61 | dict(a=range(5), b={1:b'hello'}), |
|
64 | 62 | [range(5),[range(3),(1,[b'whoda'])]], |
|
65 | 63 | ]: |
|
66 | 64 | obj2 = roundtrip(obj) |
|
67 |
|
|
|
65 | nt.assert_equal(obj, obj2) | |
|
68 | 66 | |
|
69 | @dec.parametric | |
|
70 | 67 | def test_roundtrip_buffered(): |
|
71 | 68 | for obj in [ |
|
72 | 69 | dict(a=b"x"*1025), |
@@ -74,10 +71,10 b' def test_roundtrip_buffered():' | |||
|
74 | 71 | [b"hello"*501, 1,2,3] |
|
75 | 72 | ]: |
|
76 | 73 | bufs = serialize_object(obj) |
|
77 |
|
|
|
74 | nt.assert_equal(len(bufs), 2) | |
|
78 | 75 | obj2, remainder = unserialize_object(bufs) |
|
79 |
|
|
|
80 |
|
|
|
76 | nt.assert_equal(remainder, []) | |
|
77 | nt.assert_equal(obj, obj2) | |
|
81 | 78 | |
|
82 | 79 | def _scrub_nan(A): |
|
83 | 80 | """scrub nans out of empty arrays |
@@ -93,7 +90,6 b' def _scrub_nan(A):' | |||
|
93 | 90 | # e.g. str dtype |
|
94 | 91 | pass |
|
95 | 92 | |
|
96 | @dec.parametric | |
|
97 | 93 | @dec.skip_without('numpy') |
|
98 | 94 | def test_numpy(): |
|
99 | 95 | import numpy |
@@ -104,12 +100,11 b' def test_numpy():' | |||
|
104 | 100 | _scrub_nan(A) |
|
105 | 101 | bufs = serialize_object(A) |
|
106 | 102 | B, r = unserialize_object(bufs) |
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
103 | nt.assert_equal(r, []) | |
|
104 | nt.assert_equal(A.shape, B.shape) | |
|
105 | nt.assert_equal(A.dtype, B.dtype) | |
|
106 | assert_array_equal(A,B) | |
|
111 | 107 | |
|
112 | @dec.parametric | |
|
113 | 108 | @dec.skip_without('numpy') |
|
114 | 109 | def test_recarray(): |
|
115 | 110 | import numpy |
@@ -124,12 +119,11 b' def test_recarray():' | |||
|
124 | 119 | |
|
125 | 120 | bufs = serialize_object(A) |
|
126 | 121 | B, r = unserialize_object(bufs) |
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
122 | nt.assert_equal(r, []) | |
|
123 | nt.assert_equal(A.shape, B.shape) | |
|
124 | nt.assert_equal(A.dtype, B.dtype) | |
|
125 | assert_array_equal(A,B) | |
|
131 | 126 | |
|
132 | @dec.parametric | |
|
133 | 127 | @dec.skip_without('numpy') |
|
134 | 128 | def test_numpy_in_seq(): |
|
135 | 129 | import numpy |
@@ -140,15 +134,14 b' def test_numpy_in_seq():' | |||
|
140 | 134 | _scrub_nan(A) |
|
141 | 135 | bufs = serialize_object((A,1,2,b'hello')) |
|
142 | 136 | canned = pickle.loads(bufs[0]) |
|
143 |
|
|
|
137 | nt.assert_is_instance(canned[0], CannedArray) | |
|
144 | 138 | tup, r = unserialize_object(bufs) |
|
145 | 139 | B = tup[0] |
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
140 | nt.assert_equal(r, []) | |
|
141 | nt.assert_equal(A.shape, B.shape) | |
|
142 | nt.assert_equal(A.dtype, B.dtype) | |
|
143 | assert_array_equal(A,B) | |
|
150 | 144 | |
|
151 | @dec.parametric | |
|
152 | 145 | @dec.skip_without('numpy') |
|
153 | 146 | def test_numpy_in_dict(): |
|
154 | 147 | import numpy |
@@ -159,27 +152,25 b' def test_numpy_in_dict():' | |||
|
159 | 152 | _scrub_nan(A) |
|
160 | 153 | bufs = serialize_object(dict(a=A,b=1,c=range(20))) |
|
161 | 154 | canned = pickle.loads(bufs[0]) |
|
162 |
|
|
|
155 | nt.assert_is_instance(canned['a'], CannedArray) | |
|
163 | 156 | d, r = unserialize_object(bufs) |
|
164 | 157 | B = d['a'] |
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
158 | nt.assert_equal(r, []) | |
|
159 | nt.assert_equal(A.shape, B.shape) | |
|
160 | nt.assert_equal(A.dtype, B.dtype) | |
|
161 | assert_array_equal(A,B) | |
|
169 | 162 | |
|
170 | @dec.parametric | |
|
171 | 163 | def test_class(): |
|
172 | 164 | @interactive |
|
173 | 165 | class C(object): |
|
174 | 166 | a=5 |
|
175 | 167 | bufs = serialize_object(dict(C=C)) |
|
176 | 168 | canned = pickle.loads(bufs[0]) |
|
177 |
|
|
|
169 | nt.assert_is_instance(canned['C'], CannedClass) | |
|
178 | 170 | d, r = unserialize_object(bufs) |
|
179 | 171 | C2 = d['C'] |
|
180 |
|
|
|
172 | nt.assert_equal(C2.a, C.a) | |
|
181 | 173 | |
|
182 | @dec.parametric | |
|
183 | 174 | def test_class_oldstyle(): |
|
184 | 175 | @interactive |
|
185 | 176 | class C: |
@@ -187,42 +178,38 b' def test_class_oldstyle():' | |||
|
187 | 178 | |
|
188 | 179 | bufs = serialize_object(dict(C=C)) |
|
189 | 180 | canned = pickle.loads(bufs[0]) |
|
190 |
|
|
|
181 | nt.assert_is_instance(canned['C'], CannedClass) | |
|
191 | 182 | d, r = unserialize_object(bufs) |
|
192 | 183 | C2 = d['C'] |
|
193 |
|
|
|
184 | nt.assert_equal(C2.a, C.a) | |
|
194 | 185 | |
|
195 | @dec.parametric | |
|
196 | 186 | def test_tuple(): |
|
197 | 187 | tup = (lambda x:x, 1) |
|
198 | 188 | bufs = serialize_object(tup) |
|
199 | 189 | canned = pickle.loads(bufs[0]) |
|
200 |
|
|
|
190 | nt.assert_is_instance(canned, tuple) | |
|
201 | 191 | t2, r = unserialize_object(bufs) |
|
202 |
|
|
|
192 | nt.assert_equal(t2[0](t2[1]), tup[0](tup[1])) | |
|
203 | 193 | |
|
204 | 194 | point = namedtuple('point', 'x y') |
|
205 | 195 | |
|
206 | @dec.parametric | |
|
207 | 196 | def test_namedtuple(): |
|
208 | 197 | p = point(1,2) |
|
209 | 198 | bufs = serialize_object(p) |
|
210 | 199 | canned = pickle.loads(bufs[0]) |
|
211 |
|
|
|
200 | nt.assert_is_instance(canned, point) | |
|
212 | 201 | p2, r = unserialize_object(bufs, globals()) |
|
213 |
|
|
|
214 |
|
|
|
202 | nt.assert_equal(p2.x, p.x) | |
|
203 | nt.assert_equal(p2.y, p.y) | |
|
215 | 204 | |
|
216 | @dec.parametric | |
|
217 | 205 | def test_list(): |
|
218 | 206 | lis = [lambda x:x, 1] |
|
219 | 207 | bufs = serialize_object(lis) |
|
220 | 208 | canned = pickle.loads(bufs[0]) |
|
221 |
|
|
|
209 | nt.assert_is_instance(canned, list) | |
|
222 | 210 | l2, r = unserialize_object(bufs) |
|
223 |
|
|
|
211 | nt.assert_equal(l2[0](l2[1]), lis[0](lis[1])) | |
|
224 | 212 | |
|
225 | @dec.parametric | |
|
226 | 213 | def test_class_inheritance(): |
|
227 | 214 | @interactive |
|
228 | 215 | class C(object): |
@@ -234,8 +221,8 b' def test_class_inheritance():' | |||
|
234 | 221 | |
|
235 | 222 | bufs = serialize_object(dict(D=D)) |
|
236 | 223 | canned = pickle.loads(bufs[0]) |
|
237 |
|
|
|
224 | nt.assert_is_instance(canned['D'], CannedClass) | |
|
238 | 225 | d, r = unserialize_object(bufs) |
|
239 | 226 | D2 = d['D'] |
|
240 |
|
|
|
241 |
|
|
|
227 | nt.assert_equal(D2.a, D.a) | |
|
228 | nt.assert_equal(D2.b, D.b) |
@@ -19,7 +19,6 b' from base64 import decodestring' | |||
|
19 | 19 | import nose.tools as nt |
|
20 | 20 | |
|
21 | 21 | # our own |
|
22 | from IPython.testing import decorators as dec | |
|
23 | 22 | from IPython.utils import jsonutil, tz |
|
24 | 23 | from ..jsonutil import json_clean, encode_images |
|
25 | 24 | from ..py3compat import unicode_to_str, str_to_bytes |
@@ -62,7 +61,6 b' def test():' | |||
|
62 | 61 | |
|
63 | 62 | |
|
64 | 63 | |
|
65 | @dec.parametric | |
|
66 | 64 | def test_encode_images(): |
|
67 | 65 | # invalid data, but the header and footer are from real files |
|
68 | 66 | pngdata = b'\x89PNG\r\n\x1a\nblahblahnotactuallyvalidIEND\xaeB`\x82' |
@@ -76,19 +74,19 b' def test_encode_images():' | |||
|
76 | 74 | for key, value in fmt.iteritems(): |
|
77 | 75 | # encoded has unicode, want bytes |
|
78 | 76 | decoded = decodestring(encoded[key].encode('ascii')) |
|
79 |
|
|
|
77 | nt.assert_equal(decoded, value) | |
|
80 | 78 | encoded2 = encode_images(encoded) |
|
81 |
|
|
|
79 | nt.assert_equal(encoded, encoded2) | |
|
82 | 80 | |
|
83 | 81 | b64_str = {} |
|
84 | 82 | for key, encoded in encoded.iteritems(): |
|
85 | 83 | b64_str[key] = unicode_to_str(encoded) |
|
86 | 84 | encoded3 = encode_images(b64_str) |
|
87 |
|
|
|
85 | nt.assert_equal(encoded3, b64_str) | |
|
88 | 86 | for key, value in fmt.iteritems(): |
|
89 | 87 | # encoded3 has str, want bytes |
|
90 | 88 | decoded = decodestring(str_to_bytes(encoded3[key])) |
|
91 |
|
|
|
89 | nt.assert_equal(decoded, value) | |
|
92 | 90 | |
|
93 | 91 | def test_lambda(): |
|
94 | 92 | jc = json_clean(lambda : 1) |
General Comments 0
You need to be logged in to leave comments.
Login now