Show More
@@ -20,6 +20,10 import nose.tools as nt | |||||
20 |
|
20 | |||
21 | # Our own imports |
|
21 | # Our own imports | |
22 | from .. import oinspect |
|
22 | from .. import oinspect | |
|
23 | from IPython.core.magic import (Magics, magics_class, line_magic, | |||
|
24 | cell_magic, line_cell_magic, | |||
|
25 | register_line_magic, register_cell_magic, | |||
|
26 | register_line_cell_magic) | |||
23 | from IPython.utils import py3compat |
|
27 | from IPython.utils import py3compat | |
24 |
|
28 | |||
25 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- | |
@@ -27,6 +31,7 from IPython.utils import py3compat | |||||
27 | #----------------------------------------------------------------------------- |
|
31 | #----------------------------------------------------------------------------- | |
28 |
|
32 | |||
29 | inspector = oinspect.Inspector() |
|
33 | inspector = oinspect.Inspector() | |
|
34 | ip = get_ipython() | |||
30 |
|
35 | |||
31 | #----------------------------------------------------------------------------- |
|
36 | #----------------------------------------------------------------------------- | |
32 | # Local utilities |
|
37 | # Local utilities | |
@@ -46,17 +51,50 class Call(object): | |||||
46 | def method(self, x, z=2): |
|
51 | def method(self, x, z=2): | |
47 | """Some method's docstring""" |
|
52 | """Some method's docstring""" | |
48 |
|
53 | |||
|
54 | ||||
49 | class OldStyle: |
|
55 | class OldStyle: | |
50 | """An old-style class for testing.""" |
|
56 | """An old-style class for testing.""" | |
51 | pass |
|
57 | pass | |
52 |
|
58 | |||
|
59 | ||||
53 | def f(x, y=2, *a, **kw): |
|
60 | def f(x, y=2, *a, **kw): | |
54 | """A simple function.""" |
|
61 | """A simple function.""" | |
55 |
|
62 | |||
|
63 | ||||
56 | def g(y, z=3, *a, **kw): |
|
64 | def g(y, z=3, *a, **kw): | |
57 | pass # no docstring |
|
65 | pass # no docstring | |
58 |
|
66 | |||
59 |
|
67 | |||
|
68 | @register_line_magic | |||
|
69 | def lmagic(line): | |||
|
70 | "A line magic" | |||
|
71 | ||||
|
72 | ||||
|
73 | @register_cell_magic | |||
|
74 | def cmagic(line, cell): | |||
|
75 | "A cell magic" | |||
|
76 | ||||
|
77 | ||||
|
78 | @register_line_cell_magic | |||
|
79 | def lcmagic(line, cell=None): | |||
|
80 | "A line/cell magic" | |||
|
81 | ||||
|
82 | ||||
|
83 | @magics_class | |||
|
84 | class SimpleMagics(Magics): | |||
|
85 | @line_magic | |||
|
86 | def Clmagic(self, cline): | |||
|
87 | "A class-based line magic" | |||
|
88 | ||||
|
89 | @cell_magic | |||
|
90 | def Ccmagic(self, cline, ccell): | |||
|
91 | "A class-based cell magic" | |||
|
92 | ||||
|
93 | @line_cell_magic | |||
|
94 | def Clcmagic(self, cline, ccell=None): | |||
|
95 | "A class-based line/cell magic" | |||
|
96 | ||||
|
97 | ||||
60 | def check_calltip(obj, name, call, docstring): |
|
98 | def check_calltip(obj, name, call, docstring): | |
61 | """Generic check pattern all calltip tests will use""" |
|
99 | """Generic check pattern all calltip tests will use""" | |
62 | info = inspector.info(obj, name) |
|
100 | info = inspector.info(obj, name) | |
@@ -93,6 +131,31 def test_calltip_function2(): | |||||
93 | def test_calltip_builtin(): |
|
131 | def test_calltip_builtin(): | |
94 | check_calltip(sum, 'sum', None, sum.__doc__) |
|
132 | check_calltip(sum, 'sum', None, sum.__doc__) | |
95 |
|
133 | |||
|
134 | ||||
|
135 | def test_calltip_line_magic(): | |||
|
136 | check_calltip(lmagic, 'lmagic', 'lmagic(line)', "A line magic") | |||
|
137 | ||||
|
138 | ||||
|
139 | def test_calltip_cell_magic(): | |||
|
140 | check_calltip(cmagic, 'cmagic', 'cmagic(line, cell)', "A cell magic") | |||
|
141 | ||||
|
142 | ||||
|
143 | def test_calltip_line_magic(): | |||
|
144 | check_calltip(lcmagic, 'lcmagic', 'lcmagic(line, cell=None)', | |||
|
145 | "A line/cell magic") | |||
|
146 | ||||
|
147 | ||||
|
148 | def test_class_magics(): | |||
|
149 | cm = SimpleMagics(ip) | |||
|
150 | ip.register_magics(cm) | |||
|
151 | check_calltip(cm.Clmagic, 'Clmagic', 'Clmagic(cline)', | |||
|
152 | "A class-based line magic") | |||
|
153 | check_calltip(cm.Ccmagic, 'Ccmagic', 'Ccmagic(cline, ccell)', | |||
|
154 | "A class-based cell magic") | |||
|
155 | check_calltip(cm.Clcmagic, 'Clcmagic', 'Clcmagic(cline, ccell=None)', | |||
|
156 | "A class-based line/cell magic") | |||
|
157 | ||||
|
158 | ||||
96 | def test_info(): |
|
159 | def test_info(): | |
97 | "Check that Inspector.info fills out various fields as expected." |
|
160 | "Check that Inspector.info fills out various fields as expected." | |
98 | i = inspector.info(Call, oname='Call') |
|
161 | i = inspector.info(Call, oname='Call') |
General Comments 0
You need to be logged in to leave comments.
Login now