Show More
@@ -41,6 +41,7 b' from IPython.utils.wildcard import list_namespace' | |||||
41 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable |
|
41 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable | |
42 | from IPython.utils.py3compat import cast_unicode, string_types, PY3 |
|
42 | from IPython.utils.py3compat import cast_unicode, string_types, PY3 | |
43 | from IPython.utils.colorable import Colorable |
|
43 | from IPython.utils.colorable import Colorable | |
|
44 | from IPython.utils.decorators import undoc | |||
44 |
|
45 | |||
45 | from pygments import highlight |
|
46 | from pygments import highlight | |
46 | from pygments.lexers import PythonLexer |
|
47 | from pygments.lexers import PythonLexer | |
@@ -231,31 +232,12 b' def format_argspec(argspec):' | |||||
231 | return inspect.formatargspec(argspec['args'], argspec['varargs'], |
|
232 | return inspect.formatargspec(argspec['args'], argspec['varargs'], | |
232 | argspec['varkw'], argspec['defaults']) |
|
233 | argspec['varkw'], argspec['defaults']) | |
233 |
|
234 | |||
234 |
|
235 | @undoc | ||
235 | def call_tip(oinfo, format_call=True): |
|
236 | def call_tip(oinfo, format_call=True): | |
236 | """Extract call tip data from an oinfo dict. |
|
237 | """DEPRECATED. Extract call tip data from an oinfo dict. | |
237 |
|
||||
238 | Parameters |
|
|||
239 | ---------- |
|
|||
240 | oinfo : dict |
|
|||
241 |
|
||||
242 | format_call : bool, optional |
|
|||
243 | If True, the call line is formatted and returned as a string. If not, a |
|
|||
244 | tuple of (name, argspec) is returned. |
|
|||
245 |
|
||||
246 | Returns |
|
|||
247 | ------- |
|
|||
248 | call_info : None, str or (str, dict) tuple. |
|
|||
249 | When format_call is True, the whole call information is formattted as a |
|
|||
250 | single string. Otherwise, the object's name and its argspec dict are |
|
|||
251 | returned. If no call information is available, None is returned. |
|
|||
252 |
|
||||
253 | docstring : str or None |
|
|||
254 | The most relevant docstring for calling purposes is returned, if |
|
|||
255 | available. The priority is: call docstring for callable instances, then |
|
|||
256 | constructor docstring for classes, then main object's docstring otherwise |
|
|||
257 | (regular functions). |
|
|||
258 | """ |
|
238 | """ | |
|
239 | warnings.warn('`call_tip` function is deprecated as of IPython 5.2 ' | |||
|
240 | 'and will have no effects.', DeprecationWarning, stacklevel=2) | |||
259 | # Get call definition |
|
241 | # Get call definition | |
260 | argspec = oinfo.get('argspec') |
|
242 | argspec = oinfo.get('argspec') | |
261 | if argspec is None: |
|
243 | if argspec is None: |
@@ -206,69 +206,10 b' class SerialLiar(object):' | |||||
206 | def __getattr__(self, item): |
|
206 | def __getattr__(self, item): | |
207 | return SerialLiar(self.max_fibbing_twig, self.lies_told + 1) |
|
207 | return SerialLiar(self.max_fibbing_twig, self.lies_told + 1) | |
208 |
|
208 | |||
209 |
|
||||
210 | def check_calltip(obj, name, call, docstring): |
|
|||
211 | """Generic check pattern all calltip tests will use""" |
|
|||
212 | info = inspector.info(obj, name) |
|
|||
213 | call_line, ds = oinspect.call_tip(info) |
|
|||
214 | nt.assert_equal(call_line, call) |
|
|||
215 | nt.assert_equal(ds, docstring) |
|
|||
216 |
|
||||
217 | #----------------------------------------------------------------------------- |
|
209 | #----------------------------------------------------------------------------- | |
218 | # Tests |
|
210 | # Tests | |
219 | #----------------------------------------------------------------------------- |
|
211 | #----------------------------------------------------------------------------- | |
220 |
|
212 | |||
221 | def test_calltip_class(): |
|
|||
222 | check_calltip(Call, 'Call', 'Call(x, y=1)', Call.__init__.__doc__) |
|
|||
223 |
|
||||
224 |
|
||||
225 | def test_calltip_instance(): |
|
|||
226 | c = Call(1) |
|
|||
227 | check_calltip(c, 'c', 'c(*a, **kw)', c.__call__.__doc__) |
|
|||
228 |
|
||||
229 |
|
||||
230 | def test_calltip_method(): |
|
|||
231 | c = Call(1) |
|
|||
232 | check_calltip(c.method, 'c.method', 'c.method(x, z=2)', c.method.__doc__) |
|
|||
233 |
|
||||
234 |
|
||||
235 | def test_calltip_function(): |
|
|||
236 | check_calltip(f, 'f', 'f(x, y=2, *a, **kw)', f.__doc__) |
|
|||
237 |
|
||||
238 |
|
||||
239 | def test_calltip_function2(): |
|
|||
240 | check_calltip(g, 'g', 'g(y, z=3, *a, **kw)', '<no docstring>') |
|
|||
241 |
|
||||
242 |
|
||||
243 | @skipif(sys.version_info >= (3, 5)) |
|
|||
244 | def test_calltip_builtin(): |
|
|||
245 | check_calltip(sum, 'sum', None, sum.__doc__) |
|
|||
246 |
|
||||
247 |
|
||||
248 | def test_calltip_line_magic(): |
|
|||
249 | check_calltip(lmagic, 'lmagic', 'lmagic(line)', "A line magic") |
|
|||
250 |
|
||||
251 |
|
||||
252 | def test_calltip_cell_magic(): |
|
|||
253 | check_calltip(cmagic, 'cmagic', 'cmagic(line, cell)', "A cell magic") |
|
|||
254 |
|
||||
255 |
|
||||
256 | def test_calltip_line_cell_magic(): |
|
|||
257 | check_calltip(lcmagic, 'lcmagic', 'lcmagic(line, cell=None)', |
|
|||
258 | "A line/cell magic") |
|
|||
259 |
|
||||
260 |
|
||||
261 | def test_class_magics(): |
|
|||
262 | cm = SimpleMagics(ip) |
|
|||
263 | ip.register_magics(cm) |
|
|||
264 | check_calltip(cm.Clmagic, 'Clmagic', 'Clmagic(cline)', |
|
|||
265 | "A class-based line magic") |
|
|||
266 | check_calltip(cm.Ccmagic, 'Ccmagic', 'Ccmagic(cline, ccell)', |
|
|||
267 | "A class-based cell magic") |
|
|||
268 | check_calltip(cm.Clcmagic, 'Clcmagic', 'Clcmagic(cline, ccell=None)', |
|
|||
269 | "A class-based line/cell magic") |
|
|||
270 |
|
||||
271 |
|
||||
272 | def test_info(): |
|
213 | def test_info(): | |
273 | "Check that Inspector.info fills out various fields as expected." |
|
214 | "Check that Inspector.info fills out various fields as expected." | |
274 | i = inspector.info(Call, oname='Call') |
|
215 | i = inspector.info(Call, oname='Call') |
General Comments 0
You need to be logged in to leave comments.
Login now