##// END OF EJS Templates
Fix/mpl integration (#14128)...
Fix/mpl integration (#14128) - Closes https://github.com/matplotlib/matplotlib/issues/17454 - fixes qt5/qt6 confusion

File last commit:

r28219:05f6a6e8
r28375:175d52c8 merge
Show More
test_oinspect.py
579 lines | 15.3 KiB | text/x-python | PythonLexer
Fernando Perez
Add function signature info to calltips....
r3051 """Tests for the object inspection functionality.
"""
Min RK
Get signatures directly from classes...
r22171 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Fernando Perez
Add function signature info to calltips....
r3051
Matthias Bussonnier
Support square bracket indexing with literal with pinfo/?/pinfo2/??...
r27815 from contextlib import contextmanager
Philipp A
Fix signature rendering
r24881 from inspect import signature, Signature, Parameter
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 import inspect
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290 import os
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 import pytest
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434 import re
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 import sys
Fernando Perez
Add function signature info to calltips....
r3051
from .. import oinspect
Matthias Bussonnier
Remove leftover from cleanup....
r25079
MinRK
remove decorator from external
r20813 from decorator import decorator
Matthias Bussonnier
Remove leftover from cleanup....
r25079
Min RK
include docstring in detail_level=1 if no source is found...
r23021 from IPython.testing.tools import AssertPrints, AssertNotPrints
Thomas Kluyver
Update tests for info changes
r20578 from IPython.utils.path import compress_user
Fernando Perez
Add function signature info to calltips....
r3051
Philipp A
Older versions render a little less pretty
r24882
Fernando Perez
Add function signature info to calltips....
r3051 #-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
Matthias Bussonnier
Also run test with Pytest....
r25117 inspector = None
def setup_module():
global inspector
inspector = oinspect.Inspector()
Fernando Perez
Add function signature info to calltips....
r3051
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 class SourceModuleMainTest:
__module__ = "__main__"
Fernando Perez
Add function signature info to calltips....
r3051 #-----------------------------------------------------------------------------
# Local utilities
#-----------------------------------------------------------------------------
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290 # WARNING: since this test checks the line number where a function is
# defined, if any code is inserted above, the following line will need to be
# updated. Do NOT insert any whitespace between the next line and the function
# definition below.
Matthias Bussonnier
Support square bracket indexing with literal with pinfo/?/pinfo2/??...
r27815 THIS_LINE_NUMBER = 47 # Put here the actual number of this line
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234
def test_find_source_lines():
assert oinspect.find_source_lines(test_find_source_lines) == THIS_LINE_NUMBER + 3
assert oinspect.find_source_lines(type) is None
assert oinspect.find_source_lines(SourceModuleMainTest) is None
assert oinspect.find_source_lines(SourceModuleMainTest()) is None
Matthias Bussonnier
Start refactoring handling of color....
r22911
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 def test_getsource():
assert oinspect.getsource(type) is None
assert oinspect.getsource(SourceModuleMainTest) is None
assert oinspect.getsource(SourceModuleMainTest()) is None
Matthias Bussonnier
Start refactoring handling of color....
r22911
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 def test_inspect_getfile_raises_exception():
"""Check oinspect.find_file/getsource/find_source_lines expectations"""
with pytest.raises(TypeError):
inspect.getfile(type)
with pytest.raises(OSError if sys.version_info >= (3, 10) else TypeError):
inspect.getfile(SourceModuleMainTest)
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434 # A couple of utilities to ensure these tests work the same from a source or a
# binary install
def pyfile(fname):
Jörgen Stenarson
Moving os.path.normcase call to pyfile function.
r7452 return os.path.normcase(re.sub('.py[co]$', '.py', fname))
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434
def match_pyfiles(f1, f2):
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert pyfile(f1) == pyfile(f2)
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290 def test_find_file():
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434 match_pyfiles(oinspect.find_file(test_find_file), os.path.abspath(__file__))
Nikita Kniazev
Handle OSError from inspect.getsource/getsourcelines (bpo-44648)...
r27234 assert oinspect.find_file(type) is None
assert oinspect.find_file(SourceModuleMainTest) is None
assert oinspect.find_file(SourceModuleMainTest()) is None
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290
Fernando Perez
Add extra tests for checking decorator logic with __wrapped__.
r7432 def test_find_file_decorated1():
@decorator
def noop1(f):
Min RK
deprecate IPython.utils.signatures...
r23020 def wrapper(*a, **kw):
Fernando Perez
Add extra tests for checking decorator logic with __wrapped__.
r7432 return f(*a, **kw)
return wrapper
@noop1
def f(x):
"My docstring"
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434 match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__))
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert f.__doc__ == "My docstring"
Fernando Perez
Add extra tests for checking decorator logic with __wrapped__.
r7432
def test_find_file_decorated2():
@decorator
def noop2(f, *a, **kw):
return f(*a, **kw)
@noop2
Min RK
handle multiple decorators in oinspect...
r21505 @noop2
@noop2
Fernando Perez
Add extra tests for checking decorator logic with __wrapped__.
r7432 def f(x):
"My docstring 2"
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Fernando Perez
Fix failure due to .pyc/.py mismatch detected by test_pr.
r7434 match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__))
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert f.__doc__ == "My docstring 2"
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Fernando Perez
Add extra tests for checking decorator logic with __wrapped__.
r7432
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290 def test_find_file_magic():
run = ip.find_line_magic('run')
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert oinspect.find_file(run) is not None
Fernando Perez
Fix finding of file info for magics and decorated functions....
r7290
Fernando Perez
Add function signature info to calltips....
r3051 # A few generic objects we can then inspect in the tests below
class Call(object):
"""This is the class docstring."""
def __init__(self, x, y=1):
"""This is the constructor docstring."""
def __call__(self, *a, **kw):
"""This is the call docstring."""
def method(self, x, z=2):
"""Some method's docstring"""
Bernardo B. Marques
remove all trailling spaces
r4872
Min RK
Get signatures directly from classes...
r22171 class HasSignature(object):
"""This is the class docstring."""
__signature__ = Signature([Parameter('test', Parameter.POSITIONAL_OR_KEYWORD)])
def __init__(self, *args):
"""This is the init docstring"""
Thomas Kluyver
Don't introspect __call__ for simple callables...
r15362 class SimpleClass(object):
def method(self, x, z=2):
"""Some method's docstring"""
Fernando Perez
Add tests for object inspector with magics of all types.
r6995
Thomas Kluyver
Catch some pathological cases inside oinspect...
r11058 class Awkward(object):
def __getattr__(self, name):
raise Exception(name)
Pierre Gerold
Tests thanks @carreau
r21886 class NoBoolCall:
"""
callable with `__bool__` raising should still be inspect-able.
"""
def __call__(self):
"""does nothing"""
pass
def __bool__(self):
"""just raise NotImplemented"""
raise NotImplementedError('Must be implemented')
Thomas Kluyver
Catch some pathological cases inside oinspect...
r11058
Thomas Kluyver
Add test for infinite looping on attribute access
r21906 class SerialLiar(object):
"""Attribute accesses always get another copy of the same class.
unittest.mock.call does something similar, but it's not ideal for testing
as the failure mode is to eat all your RAM. This gives up after 10k levels.
"""
def __init__(self, max_fibbing_twig, lies_told=0):
if lies_told > 10000:
raise RuntimeError('Nose too long, honesty is the best policy')
self.max_fibbing_twig = max_fibbing_twig
self.lies_told = lies_told
max_fibbing_twig[0] = max(max_fibbing_twig[0], lies_told)
def __getattr__(self, item):
return SerialLiar(self.max_fibbing_twig, self.lies_told + 1)
Fernando Perez
Add function signature info to calltips....
r3051 #-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 def test_info():
"Check that Inspector.info fills out various fields as expected."
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 i = inspector.info(Call, oname="Call")
assert i["type_name"] == "type"
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 expected_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'>
assert i["base_class"] == expected_class
assert re.search(
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>",
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 i["string_form"],
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 )
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 fname = __file__
if fname.endswith(".pyc"):
fname = fname[:-1]
Min RK
fix various tests on Windows...
r4105 # case-insensitive comparison needed on some filesystems
# e.g. Windows:
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert i["file"].lower() == compress_user(fname).lower()
assert i["definition"] == None
assert i["docstring"] == Call.__doc__
assert i["source"] == None
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert i["isclass"] is True
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert i["init_definition"] == "Call(x, y=1)"
assert i["init_docstring"] == Call.__init__.__doc__
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 i = inspector.info(Call, detail_level=1)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert i["source"] is not None
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert i["docstring"] == None
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 c = Call(1)
c.__doc__ = "Modified instance docstring"
i = inspector.info(c)
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert i["type_name"] == "Call"
assert i["docstring"] == "Modified instance docstring"
assert i["class_docstring"] == Call.__doc__
assert i["init_docstring"] == Call.__init__.__doc__
assert i["call_docstring"] == Call.__call__.__doc__
Bernardo B. Marques
remove all trailling spaces
r4872
Min RK
Get signatures directly from classes...
r22171 def test_class_signature():
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 info = inspector.info(HasSignature, "HasSignature")
assert info["init_definition"] == "HasSignature(test)"
assert info["init_docstring"] == HasSignature.__init__.__doc__
Min RK
Get signatures directly from classes...
r22171
Thomas Kluyver
Catch some pathological cases inside oinspect...
r11058 def test_info_awkward():
# Just test that this doesn't throw an error.
Matthias Bussonnier
Fix test failing because of extra newline.
r22536 inspector.info(Awkward())
Thomas Kluyver
Catch some pathological cases inside oinspect...
r11058
Pierre Gerold
Tests thanks @carreau
r21886 def test_bool_raise():
inspector.info(NoBoolCall())
Thomas Kluyver
Add test for infinite looping on attribute access
r21906 def test_info_serialliar():
fib_tracker = [0]
Matthias Bussonnier
Start refactoring handling of color....
r22911 inspector.info(SerialLiar(fib_tracker))
Thomas Kluyver
Add test for infinite looping on attribute access
r21906
# Nested attribute access should be cut off at 100 levels deep to avoid
# infinite loops: https://github.com/ipython/ipython/issues/9122
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert fib_tracker[0] < 9000
Thomas Kluyver
Add test for infinite looping on attribute access
r21906
Matthias Bussonnier
Remove more unused support functions and class
r25081 def support_function_one(x, y=2, *a, **kw):
"""A simple function."""
Thomas Kluyver
Don't introspect __call__ for simple callables...
r15362 def test_calldef_none():
# We should ignore __call__ for all of these.
Matthias Bussonnier
Remove more unused support functions and class
r25081 for obj in [support_function_one, SimpleClass().method, any, str.upper]:
Thomas Kluyver
Don't introspect __call__ for simple callables...
r15362 i = inspector.info(obj)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert i["call_def"] is None
Thomas Kluyver
Don't introspect __call__ for simple callables...
r15362
Matthias Bussonnier
Start refactoring handling of color....
r22911 def f_kwarg(pos, *, kwonly):
pass
Thomas Kluyver
Fix the display of functions with keyword-only arguments on Python 3.
r15335
def test_definition_kwonlyargs():
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 i = inspector.info(f_kwarg, oname="f_kwarg") # analysis:ignore
assert i["definition"] == "f_kwarg(pos, *, kwonly)"
Thomas Kluyver
Fix the display of functions with keyword-only arguments on Python 3.
r15335
Thomas Kluyver
Add test for oinspect.getdoc
r5538 def test_getdoc():
class A(object):
"""standard docstring"""
pass
Sylvain Corlay
pinfo magic return mime bundle
r22460
Thomas Kluyver
Add test for oinspect.getdoc
r5538 class B(object):
"""standard docstring"""
def getdoc(self):
return "custom docstring"
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Thomas Kluyver
Test for getdoc() returning None.
r5573 class C(object):
"""standard docstring"""
def getdoc(self):
return None
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Thomas Kluyver
Add test for oinspect.getdoc
r5538 a = A()
b = B()
Thomas Kluyver
Test for getdoc() returning None.
r5573 c = C()
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert oinspect.getdoc(a) == "standard docstring"
assert oinspect.getdoc(b) == "custom docstring"
assert oinspect.getdoc(c) == "standard docstring"
Thomas Kluyver
Add failing test for gh-1914
r7460
immerrr
Print sources for property fget/fset/fdel methods...
r17023
def test_empty_property_has_no_source():
i = inspector.info(property(), detail_level=1)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert i["source"] is None
immerrr
Print sources for property fget/fset/fdel methods...
r17023
def test_property_sources():
madhu94
Add signature to the display of functions in the shell
r24026 # A simple adder whose source and signature stays
# the same across Python distributions
def simple_add(a, b):
"Adds two numbers"
return a + b
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
immerrr
Print sources for property fget/fset/fdel methods...
r17023 class A(object):
@property
def foo(self):
return 'bar'
foo = foo.setter(lambda self, v: setattr(self, 'bar', v))
Nikita Kniazev
Python 3.11 fixes
r27105 dname = property(oinspect.getdoc)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 adder = property(simple_add)
immerrr
Print sources for property fget/fset/fdel methods...
r17023
i = inspector.info(A.foo, detail_level=1)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert "def foo(self):" in i["source"]
assert "lambda self, v:" in i["source"]
immerrr
Print sources for property fget/fset/fdel methods...
r17023
madhu94
Add signature to the display of functions in the shell
r24026 i = inspector.info(A.dname, detail_level=1)
Nikita Kniazev
Python 3.11 fixes
r27105 assert "def getdoc(obj)" in i["source"]
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
madhu94
Add signature to the display of functions in the shell
r24026 i = inspector.info(A.adder, detail_level=1)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert "def simple_add(a, b)" in i["source"]
immerrr
Print sources for property fget/fset/fdel methods...
r17023
def test_property_docstring_is_in_info_for_detail_level_0():
class A(object):
@property
Matthias Bussonnier
A few style fixes:...
r22354 def foobar(self):
immerrr
Print sources for property fget/fset/fdel methods...
r17023 """This is `foobar` property."""
pass
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 ip.user_ns["a_obj"] = A()
assert (
"This is `foobar` property."
== ip.object_inspect("a_obj.foobar", detail_level=0)["docstring"]
)
immerrr
Print sources for property fget/fset/fdel methods...
r17023
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 ip.user_ns["a_cls"] = A
assert (
"This is `foobar` property."
== ip.object_inspect("a_cls.foobar", detail_level=0)["docstring"]
)
immerrr
Print sources for property fget/fset/fdel methods...
r17023
Thomas Kluyver
Add failing test for gh-1914
r7460 def test_pdef():
# See gh-1914
def foo(): pass
inspector.pdef(foo, 'foo')
Thomas Kluyver
Add test for non-ascii characters in docstrings...
r11067
Min RK
get signature from init if top-level signature fails...
r22539
Matthias Bussonnier
Support square bracket indexing with literal with pinfo/?/pinfo2/??...
r27815 @contextmanager
def cleanup_user_ns(**kwargs):
"""
On exit delete all the keys that were not in user_ns before entering.
It does not restore old values !
Parameters
----------
**kwargs
used to update ip.user_ns
"""
try:
known = set(ip.user_ns.keys())
ip.user_ns.update(kwargs)
yield
finally:
added = set(ip.user_ns.keys()) - known
for k in added:
del ip.user_ns[k]
Matthias Bussonnier
Add failing test is __bool__ is called on parent
r28210 def test_pinfo_bool_raise():
"""
Test that bool method is not called on parent.
"""
class RaiseBool:
attr = None
def __bool__(self):
raise ValueError("pinfo should not access this method")
raise_bool = RaiseBool()
with cleanup_user_ns(raise_bool=raise_bool):
ip._inspect("pinfo", "raise_bool.attr", detail_level=0)
Matthias Bussonnier
Support square bracket indexing with literal with pinfo/?/pinfo2/??...
r27815 def test_pinfo_getindex():
def dummy():
"""
MARKER
"""
container = [dummy]
with cleanup_user_ns(container=container):
with AssertPrints("MARKER"):
ip._inspect("pinfo", "container[0]", detail_level=0)
assert "container" not in ip.user_ns.keys()
def test_qmark_getindex():
def dummy():
"""
MARKER 2
"""
container = [dummy]
with cleanup_user_ns(container=container):
with AssertPrints("MARKER 2"):
ip.run_cell("container[0]?")
assert "container" not in ip.user_ns.keys()
Matthias Bussonnier
formatting
r27819
Matthias Bussonnier
support negative indexing
r27818 def test_qmark_getindex_negatif():
def dummy():
"""
MARKER 3
"""
container = [dummy]
with cleanup_user_ns(container=container):
with AssertPrints("MARKER 3"):
ip.run_cell("container[-1]?")
assert "container" not in ip.user_ns.keys()
Matthias Bussonnier
Support square bracket indexing with literal with pinfo/?/pinfo2/??...
r27815
Thomas Kluyver
Add test for non-ascii characters in docstrings...
r11067 def test_pinfo_nonascii():
# See gh-1177
from . import nonascii2
ip.user_ns['nonascii2'] = nonascii2
ip._inspect('pinfo', 'nonascii2', detail_level=1)
Thomas Kluyver
Add test for pinfo with magics
r20699
Matthias Bussonnier
Handle edge case when requesting subclasses....
r24946 def test_pinfo_type():
"""
type can fail in various edge case, for example `type.__subclass__()`
"""
ip._inspect('pinfo', 'type')
Min RK
get signature from init if top-level signature fails...
r22539
Min RK
include docstring in detail_level=1 if no source is found...
r23021 def test_pinfo_docstring_no_source():
"""Docstring should be included with detail_level=1 if there is no source"""
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'str.format', detail_level=0)
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'str.format', detail_level=1)
def test_pinfo_no_docstring_if_source():
"""Docstring should not be included with detail_level=1 if source is found"""
def foo():
"""foo has a docstring"""
ip.user_ns['foo'] = foo
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'foo', detail_level=0)
with AssertPrints('Source:'):
ip._inspect('pinfo', 'foo', detail_level=1)
with AssertNotPrints('Docstring:'):
ip._inspect('pinfo', 'foo', detail_level=1)
ryan thielke
Add test for ?? to show docstring if no source code available #10534
r23660 def test_pinfo_docstring_if_detail_and_no_source():
""" Docstring should be displayed if source info not available """
obj_def = '''class Foo(object):
""" This is a docstring for Foo """
def bar(self):
""" This is a docstring for Foo.bar """
pass
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 '''
ryan thielke
Add test for ?? to show docstring if no source code available #10534
r23660 ip.run_cell(obj_def)
ip.run_cell('foo = Foo()')
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904
ryan thielke
Add test for ?? to show docstring if no source code available #10534
r23660 with AssertNotPrints("Source:"):
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'foo', detail_level=0)
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'foo', detail_level=1)
with AssertPrints('Docstring:'):
ip._inspect('pinfo', 'foo.bar', detail_level=0)
with AssertNotPrints('Docstring:'):
with AssertPrints('Source:'):
ip._inspect('pinfo', 'foo.bar', detail_level=1)
Matthias Bussonnier
Allow to dispatch getting documentation on objects...
r28195 def test_pinfo_docstring_dynamic():
obj_def = """class Bar:
__custom_documentations__ = {
"prop" : "cdoc for prop",
"non_exist" : "cdoc for non_exist",
}
@property
def prop(self):
'''
Docstring for prop
'''
return self._prop
@prop.setter
def prop(self, v):
self._prop = v
"""
ip.run_cell(obj_def)
ip.run_cell("b = Bar()")
with AssertPrints("Docstring: cdoc for prop"):
ip.run_line_magic("pinfo", "b.prop")
with AssertPrints("Docstring: cdoc for non_exist"):
ip.run_line_magic("pinfo", "b.non_exist")
with AssertPrints("Docstring: cdoc for prop"):
ip.run_cell("b.prop?")
with AssertPrints("Docstring: cdoc for non_exist"):
ip.run_cell("b.non_exist?")
with AssertPrints("Docstring: <no docstring>"):
ip.run_cell("b.undefined?")
Thomas Kluyver
Add test for pinfo with magics
r20699 def test_pinfo_magic():
Matthias Bussonnier
Allow to dispatch getting documentation on objects...
r28195 with AssertPrints("Docstring:"):
ip._inspect("pinfo", "lsmagic", detail_level=0)
Thomas Kluyver
Add test for pinfo with magics
r20699
Matthias Bussonnier
Allow to dispatch getting documentation on objects...
r28195 with AssertPrints("Source:"):
ip._inspect("pinfo", "lsmagic", detail_level=1)
Min RK
get signature from init if top-level signature fails...
r22539
def test_init_colors():
# ensure colors are not present in signature info
info = inspector.info(HasSignature)
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 init_def = info["init_definition"]
assert "[0m" not in init_def
Min RK
get signature from init if top-level signature fails...
r22539
def test_builtin_init():
info = inspector.info(list)
init_def = info['init_definition']
Samuel Gaist
[core][tests][oinspect] Remove nose
r26904 assert init_def is not None
Min RK
get signature from init if top-level signature fails...
r22539
Philipp A
Fix signature rendering
r24881
def test_render_signature_short():
Philipp A
Older versions render a little less pretty
r24882 def short_fun(a=1): pass
Philipp A
Fix signature rendering
r24881 sig = oinspect._render_signature(
signature(short_fun),
short_fun.__name__,
)
Matthias Bussonnier
remove nose.assert_equal from IPython/core/tests/test_oinspect.py
r26724 assert sig == "short_fun(a=1)"
Philipp A
Fix signature rendering
r24881
def test_render_signature_long():
from typing import Optional
def long_function(
a_really_long_parameter: int,
and_another_long_one: bool = False,
let_us_make_sure_this_is_looong: Optional[str] = None,
) -> bool: pass
sig = oinspect._render_signature(
signature(long_function),
long_function.__name__,
)
Matthias Bussonnier
MAINT: remove support and testing on Python 3.8...
r28219 expected = """\
Matthias Bussonnier
Fix some test on python 3.9 (nightly)....
r25719 long_function(
a_really_long_parameter: int,
and_another_long_one: bool = False,
let_us_make_sure_this_is_looong: Optional[str] = None,
) -> bool\
Matthias Bussonnier
explict python version check
r28176 """
Matthias Bussonnier
MAINT: remove support and testing on Python 3.8...
r28219
Matthias Bussonnier
explict python version check
r28176 assert sig == expected