Ejemplo n.º 1
0
def _get_object_pydoc_page_name(obj):
    """Returns fully qualified name, including module name, except for the
    built-in module."""
    page_name = fullqualname.fullqualname(obj)
    if page_name is not None:
       page_name = _remove_builtin_prefix(page_name)
    return page_name
Ejemplo n.º 2
0
def test_class_instance():
    # Test class instance object.

    obj = C_()

    expected = __name__ + '.C_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 3
0
def test_module():
    # Test module object.

    obj = sys
    assert type(obj).__name__ == 'module'

    expected = 'sys'
    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 4
0
def test_class():
    # Test class object.

    obj = C_

    assert inspect.isclass(obj)

    expected = __name__ + '.C_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 5
0
def test_member_descriptor():
    # Test member descriptor object.

    obj = datetime.timedelta.days

    assert type(obj).__name__ == 'member_descriptor'

    expected = 'datetime.timedelta.days'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 6
0
def test_function():
    # Test function object.

    obj = func_

    assert type(obj).__name__ == 'function'

    expected = __name__ + '.func_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 7
0
def test_wrapper_descriptor():
    # Test wrapper descriptor object.

    obj = int.__add__

    assert type(obj).__name__ == 'wrapper_descriptor'

    if sys.version_info >= (3, ):
        expected = 'builtins.int.__add__'
    else:
        expected = '__builtin__.int.__add__'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 8
0
def test_method_descriptor():
    # Test method descriptor object.

    obj = str.split

    assert type(obj).__name__ == 'method_descriptor'

    if sys.version_info >= (3, ):
        expected = 'builtins.str.split'
    else:
        expected = '__builtin__.str.split'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 9
0
def test_method_wrapper():
    # Test 'method-wrapper' object.

    obj = [].__add__

    # Type 'method-wrapper' is only defined in CPython.
    assert type(obj).__name__ == 'method-wrapper'

    if sys.version_info >= (3, ):
        expected = 'builtins.list.__add__'
    else:
        expected = '__builtin__.list.__add__'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 10
0
def test_function_wrapped_attribute():
    # Test function object that has a __wrapped__ attribute.

    obj = C_.decorated_method_

    assert hasattr(obj, '__wrapped__')

    # In Python 3, object type is 'function'.
    assert type(obj).__name__ == 'function' or sys.version_info[0] == 2

    # In Python 2, object is an 'instancemethod'.
    assert type(obj).__name__ == 'instancemethod' or sys.version_info[0] == 3

    expected = __name__ + '.C_.decorated_method_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 11
0
def test_builtin_function():
    # Test built-in function object.

    obj = len

    # Type is 'builtin_function_or_method'.
    assert type(obj).__name__ == 'builtin_function_or_method'

    # Object is a function.
    assert 'built-in function' in repr(obj)

    if sys.version_info >= (3, ):
        expected = 'builtins.len'
    else:
        expected = '__builtin__.len'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 12
0
def test_unbound_method_py2():
    # Test unbound method object (Python 2).

    obj = C_.method_

    # In Python 2, the object is an unbound method.
    # Its '__self__' attribute is None.
    # (https://docs.python.org/2/reference/datamodel.html).
    assert type(obj).__name__ == 'instancemethod' and \
        obj.__self__ is None or sys.version_info[0] > 2

    # In Python 3, object is a function.
    assert type(obj).__name__ == 'function' or sys.version_info[0] == 2

    expected = __name__ + '.C_.method_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 13
0
def test_property():
    # Test property object.
    # Python 2 does not support introspection for properties.

    obj = C_.property_

    assert type(obj).__name__ == 'property'

    # Property object has a fget attribute.
    assert hasattr(obj, 'fget')

    if sys.version_info.major == 3:
        expected = __name__ + '.C_.property_'
    else:
        expected = '__builtin__.property'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 14
0
def test_builtin_classmethod():
    # Test built-in class method object.

    obj = object.mro

    # Object type is 'builtin_function_or_method'.
    assert type(obj).__name__ == 'builtin_function_or_method'

    # Object is a method.
    assert 'built-in method' in repr(obj)

    # Object __self__ attribute is a class.
    assert inspect.isclass(obj.__self__)

    if sys.version_info >= (3, ):
        expected = 'builtins.object.mro'
    else:
        expected = '__builtin__.object.mro'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 15
0
def test_method_self_is_not_a_class():
    # Test method object whose __self__ attribute is not a class.

    obj = C_().method_

    # Object is an 'instance method'.
    assert inspect.ismethod(obj)

    # Object is an 'instance method' in Python 2.
    assert type(obj).__name__ == 'instancemethod' or sys.version_info[0] != 2

    # Object is a 'method' in Python 3.
    assert type(obj).__name__ == 'method' or sys.version_info[0] < 3

    # '__self__' attribute is not a class.
    assert not inspect.isclass(obj.__self__)

    expected = __name__ + '.C_.method_'

    nose.tools.assert_equals(fullqualname(obj), expected)
Ejemplo n.º 16
0
def test_method_self_is_a_class():
    # Test method object whose __self__ attribute is a class.

    obj = C_.classmethod_

    # Object is an 'instance method'
    assert inspect.ismethod(obj)

    # Object is not an instance of 'classmethod'.
    assert not isinstance(obj, classmethod)

    # Type of object is 'instancemethod' in Python 2.
    assert type(obj).__name__ == 'instancemethod' or sys.version_info[0] != 2

    # Type of object is 'method' in Python 3+.
    assert type(obj).__name__ == 'method' or sys.version_info[0] == 2

    # The '__self__' attribute is a class.
    assert inspect.isclass(obj.__self__)

    expected = __name__ + '.C_.classmethod_'

    nose.tools.assert_equals(fullqualname(obj), expected)