Show More
@@ -305,8 +305,13 b' def test_empty_property_has_no_source():' | |||
|
305 | 305 | |
|
306 | 306 | |
|
307 | 307 | def test_property_sources(): |
|
308 |
import |
|
|
309 | ||
|
308 | import posixpath | |
|
309 | # A simple adder whose source and signature stays | |
|
310 | # the same across Python distributions | |
|
311 | def simple_add(a, b): | |
|
312 | "Adds two numbers" | |
|
313 | return a + b | |
|
314 | ||
|
310 | 315 | class A(object): |
|
311 | 316 | @property |
|
312 | 317 | def foo(self): |
@@ -314,18 +319,18 b' def test_property_sources():' | |||
|
314 | 319 | |
|
315 | 320 | foo = foo.setter(lambda self, v: setattr(self, 'bar', v)) |
|
316 | 321 | |
|
317 |
|
|
|
318 |
|
|
|
322 | dname = property(posixpath.dirname) | |
|
323 | adder = property(simple_add) | |
|
319 | 324 | |
|
320 | 325 | i = inspector.info(A.foo, detail_level=1) |
|
321 | 326 | nt.assert_in('def foo(self):', i['source']) |
|
322 | 327 | nt.assert_in('lambda self, v:', i['source']) |
|
323 | 328 | |
|
324 |
i = inspector.info(A. |
|
|
325 |
nt.assert_in(' |
|
|
326 | ||
|
327 |
i = inspector.info(A. |
|
|
328 |
nt.assert_in(' |
|
|
329 | i = inspector.info(A.dname, detail_level=1) | |
|
330 | nt.assert_in('def dirname(p)', i['source']) | |
|
331 | ||
|
332 | i = inspector.info(A.adder, detail_level=1) | |
|
333 | nt.assert_in('def simple_add(a, b)', i['source']) | |
|
329 | 334 | |
|
330 | 335 | |
|
331 | 336 | def test_property_docstring_is_in_info_for_detail_level_0(): |
@@ -88,7 +88,7 b' from warnings import warn' | |||
|
88 | 88 | |
|
89 | 89 | from IPython.utils.decorators import undoc |
|
90 | 90 | from IPython.utils.py3compat import PYPY |
|
91 | ||
|
91 | from IPython.utils.signatures import signature | |
|
92 | 92 | |
|
93 | 93 | __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter', |
|
94 | 94 | 'for_type', 'for_type_by_name'] |
@@ -711,7 +711,11 b' def _function_pprint(obj, p, cycle):' | |||
|
711 | 711 | mod = obj.__module__ |
|
712 | 712 | if mod and mod not in ('__builtin__', 'builtins', 'exceptions'): |
|
713 | 713 | name = mod + '.' + name |
|
714 | p.text('<function %s>' % name) | |
|
714 | try: | |
|
715 | func_def = name + str(signature(obj)) | |
|
716 | except ValueError: | |
|
717 | func_def = name | |
|
718 | p.text('<function %s>' % func_def) | |
|
715 | 719 | |
|
716 | 720 | |
|
717 | 721 | def _exception_pprint(obj, p, cycle): |
@@ -405,3 +405,19 b' def test_mappingproxy():' | |||
|
405 | 405 | ] |
|
406 | 406 | for obj, expected in cases: |
|
407 | 407 | nt.assert_equal(pretty.pretty(obj), expected) |
|
408 | ||
|
409 | def test_function_pretty(): | |
|
410 | "Test pretty print of function" | |
|
411 | # posixpath is a pure python function, its interface is consistent | |
|
412 | # across Python distributions | |
|
413 | import os | |
|
414 | nt.assert_equal(pretty.pretty(os.path.join), '<function posixpath.join(a, *p)>') | |
|
415 | ||
|
416 | # custom function | |
|
417 | def meaning_of_life(question=None): | |
|
418 | if question: | |
|
419 | return 42 | |
|
420 | return "Don't panic" | |
|
421 | ||
|
422 | nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life)) | |
|
423 |
General Comments 0
You need to be logged in to leave comments.
Login now