def test_handles_exceptions_containing_user_objects(self):
        def function():
            class Something(object):
                pass
            def returning_exception_with_something():
                return OverflowError(Something())
            returning_exception_with_something()
        callables = inspect_returning_callables(function)
        function = findfirst(is_function, callables)
        user_object = findfirst(is_user_object, callables)

        call = assert_one_element_and_return(function.calls)
        user_object_in_exc = assert_one_element_and_return(call.output.args)
        assert user_object is user_object_in_exc
示例#2
0
    def test_handles_exceptions_containing_user_objects(self):
        def function():
            class Something(object):
                pass
            def returning_exception_with_something():
                return OverflowError(Something())
            returning_exception_with_something()
        callables = inspect_returning_callables(function)
        function = findfirst(is_function, callables)
        user_object = findfirst(is_user_object, callables)

        call = assert_one_element_and_return(function.calls)
        user_object_in_exc = assert_one_element_and_return(call.output.args)
        assert user_object is user_object_in_exc
    def test_handles_functions_which_raise_user_defined_exceptions(self):
        def function_raising_a_user_defined_exception():
            class UserDefinedException(Exception):
                pass
            def function(x):
                raise UserDefinedException()
            function(42)
        callables = inspect_returning_callables(function_raising_a_user_defined_exception)
        function = findfirst(is_function, callables)

        assert_call_with_exception({'x': 42}, 'UserDefinedException', function.calls[0])
    def test_handles_passing_user_objects_around(self):
        def fun():
            class Something(object):
                pass
            def compare(x, y):
                return x is y
            obj = Something()
            compare(obj, obj)

        callables = inspect_returning_callables(fun)
        assert_length(callables, 2)

        user_object = findfirst(is_user_object, callables)

        function = findfirst(is_function, callables)
        call = assert_one_element_and_return(function.calls)

        assert_instance(call.output, ImmutableObject)
        assert_equal(ImmutableObject(True), call.output)
        assert call.input['x'] is call.input['y'] is user_object
示例#5
0
    def test_handles_functions_which_raise_user_defined_exceptions(self):
        def function_raising_a_user_defined_exception():
            class UserDefinedException(Exception):
                pass
            def function(x):
                raise UserDefinedException()
            function(42)
        callables = inspect_returning_callables(function_raising_a_user_defined_exception)
        function = findfirst(is_function, callables)

        assert_call_with_exception({'x': 42}, 'UserDefinedException', function.calls[0])
示例#6
0
    def test_handles_passing_user_objects_around(self):
        def fun():
            class Something(object):
                pass
            def compare(x, y):
                return x is y
            obj = Something()
            compare(obj, obj)

        callables = inspect_returning_callables(fun)
        assert_length(callables, 2)

        user_object = findfirst(is_user_object, callables)

        function = findfirst(is_function, callables)
        call = assert_one_element_and_return(function.calls)

        assert_instance(call.output, ImmutableObject)
        assert_equal(ImmutableObject(True), call.output)
        assert call.input['x'] is call.input['y'] is user_object
示例#7
0
 def get_init_call(self):
     """Return a call to __init__ or None if it wasn't called.
     """
     return findfirst(lambda call: call.definition.name == '__init__',
                      self.calls)
def find_first_with_name(name, collection):
    return findfirst(lambda f: f.name == name, collection)
示例#9
0
文件: store.py 项目: goulu/pythoscope
 def get_init_call(self):
     """Return a call to __init__ or None if it wasn't called.
     """
     return findfirst(lambda call: call.definition.name == '__init__', self.calls)
示例#10
0
def find_first_with_name(name, collection):
    return findfirst(lambda f: f.name == name, collection)