Example #1
0
def test_function_name_callable_object():
    """Use __call__ method and instance as is for callable objects."""

    kallable = CallableObject()
    func_name, instance = function_name(kallable)
    assert func_name == '__call__'
    assert instance is kallable
Example #2
0
def test_function_name_instance_method():
    """Use method __name__ and method __self__ attributes."""

    n = Number(2)
    func_name, instance = function_name(n.div)
    assert func_name == 'div'
    assert instance is n
Example #3
0
def test_function_name_callable_object():
    """Use __call__ method and instance as is for callable objects."""

    kallable = CallableObject()
    func_name, instance = function_name(kallable)
    assert func_name == '__call__'
    assert instance is kallable
Example #4
0
def test_function_name_instance_method():
    """Use method __name__ and method __self__ attributes."""

    n = Number(2)
    func_name, instance = function_name(n.div)
    assert func_name == 'div'
    assert instance is n
Example #5
0
def test_function_name_regular_function():
    """Use __module__ together with __name__ attribute for regular
    function.
    """

    func_name, instance = function_name(some_calculation)
    assert func_name == 'fixtures.some_calculation'
    assert instance is None
Example #6
0
def test_function_name_regular_function():
    """Use __module__ together with __name__ attribute for regular
    function.
    """

    func_name, instance = function_name(some_calculation)
    assert func_name == 'fixtures.some_calculation'
    assert instance is None
Example #7
0
def test_function_name_not_a_function():
    """Raise exception in the case argument can't be a function."""

    with pytest.raises(TypeError):
        function_name(1)
Example #8
0
def test_function_name_builtin():
    """Use builtins module for global objects."""

    func_name, instance = function_name(len)
    assert func_name == 'builtins.len'
    assert instance is None
Example #9
0
def test_function_name_bytes_function():
    """Use decoded bytes as function name."""

    func_name, instance = function_name(b'fixtures.say_hello')
    assert func_name == 'fixtures.say_hello'
    assert instance is None
Example #10
0
def test_function_name_string_function():
    """Use function name as is."""

    func_name, instance = function_name('fixtures.say_hello')
    assert func_name == 'fixtures.say_hello'
    assert instance is None
Example #11
0
def test_function_name_not_a_function():
    """Raise exception in the case argument can't be a function."""

    with pytest.raises(TypeError):
        function_name(1)
Example #12
0
def test_function_name_builtin():
    """Use builtins module for global objects."""

    func_name, instance = function_name(len)
    assert func_name == 'builtins.len'
    assert instance is None
Example #13
0
def test_function_name_bytes_function():
    """Use decoded bytes as function name."""

    func_name, instance = function_name(b'fixtures.say_hello')
    assert func_name == 'fixtures.say_hello'
    assert instance is None
Example #14
0
def test_function_name_string_function():
    """Use function name as is."""

    func_name, instance = function_name('fixtures.say_hello')
    assert func_name == 'fixtures.say_hello'
    assert instance is None