##// END OF EJS Templates
Merge pull request #937 from minrk/readline...
Merge pull request #937 from minrk/readline Add dirty trick for readline import on OSX to more aggressively detect the presence of libedit masquerading as true GNU readline. Also made the libedit warning extremely loud, so people don't miss it. See the original PR page for the gory details; short version: 1. remove lib-dynload from sys.path before trying to import readline the first time 2. after import, restore lib-dynload to its place in sys.path 3. if import failed without lib-dynload, try it one more time, to get the default module

File last commit:

r4872:34c10438
r5211:90b01394 merge
Show More
test_oinspect.py
136 lines | 4.4 KiB | text/x-python | PythonLexer
Fernando Perez
Add function signature info to calltips....
r3051 """Tests for the object inspection functionality.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2010 The IPython Development Team.
#
# Distributed under the terms of the BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
# Stdlib imports
# Third-party imports
import nose.tools as nt
# Our own imports
from .. import oinspect
Thomas Kluyver
test_oinspect works with Python 3.
r4760 from IPython.utils import py3compat
Fernando Perez
Add function signature info to calltips....
r3051
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
inspector = oinspect.Inspector()
#-----------------------------------------------------------------------------
# Local utilities
#-----------------------------------------------------------------------------
# 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
Thomas Kluyver
Tweak Inspector.info() so it doesn't fail on old style classes. Added test....
r3867 class OldStyle:
"""An old-style class for testing."""
pass
Fernando Perez
Add function signature info to calltips....
r3051
def f(x, y=2, *a, **kw):
"""A simple function."""
def g(y, z=3, *a, **kw):
pass # no docstring
def check_calltip(obj, name, call, docstring):
"""Generic check pattern all calltip tests will use"""
info = inspector.info(obj, name)
call_line, ds = oinspect.call_tip(info)
nt.assert_equal(call_line, call)
Bernardo B. Marques
remove all trailling spaces
r4872 nt.assert_equal(ds, docstring)
Fernando Perez
Add function signature info to calltips....
r3051
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
def test_calltip_class():
check_calltip(Call, 'Call', 'Call(x, y=1)', Call.__init__.__doc__)
def test_calltip_instance():
c = Call(1)
check_calltip(c, 'c', 'c(*a, **kw)', c.__call__.__doc__)
def test_calltip_method():
c = Call(1)
check_calltip(c.method, 'c.method', 'c.method(x, z=2)', c.method.__doc__)
def test_calltip_function():
check_calltip(f, 'f', 'f(x, y=2, *a, **kw)', f.__doc__)
def test_calltip_function2():
check_calltip(g, 'g', 'g(y, z=3, *a, **kw)', '<no docstring>')
def test_calltip_builtin():
check_calltip(sum, 'sum', None, sum.__doc__)
Bernardo B. Marques
remove all trailling spaces
r4872
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."
i = inspector.info(Call, oname='Call')
nt.assert_equal(i['type_name'], 'type')
Thomas Kluyver
test_oinspect works with Python 3.
r4760 expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'>
nt.assert_equal(i['base_class'], expted_class)
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 nt.assert_equal(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'>")
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:
nt.assert_equal(i['file'].lower(), fname.lower())
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 nt.assert_equal(i['definition'], 'Call(self, *a, **kw)\n')
nt.assert_equal(i['docstring'], Call.__doc__)
Thomas Kluyver
Tweak test_oinspect to only use a common subset of nt.assert_* functions.
r3869 nt.assert_equal(i['source'], None)
Thomas Kluyver
Add test that Inspector.info fills out various fields as expected.
r3859 nt.assert_true(i['isclass'])
nt.assert_equal(i['init_definition'], "Call(self, x, y=1)\n")
nt.assert_equal(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)
Thomas Kluyver
Tweak test_oinspect to only use a common subset of nt.assert_* functions.
r3869 nt.assert_not_equal(i['source'], None)
nt.assert_equal(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)
nt.assert_equal(i['type_name'], 'Call')
nt.assert_equal(i['docstring'], "Modified instance docstring")
nt.assert_equal(i['class_docstring'], Call.__doc__)
nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
nt.assert_equal(i['call_docstring'], c.__call__.__doc__)
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Tweak Inspector.info() so it doesn't fail on old style classes. Added test....
r3867 # Test old-style classes, which for example may not have an __init__ method.
Thomas Kluyver
test_oinspect works with Python 3.
r4760 if not py3compat.PY3:
i = inspector.info(OldStyle)
nt.assert_equal(i['type_name'], 'classobj')
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
test_oinspect works with Python 3.
r4760 i = inspector.info(OldStyle())
nt.assert_equal(i['type_name'], 'instance')
nt.assert_equal(i['docstring'], OldStyle.__doc__)