Example #1
0
    def test_returns_sentinel_when_exception_is_raised(self):
        exception_class = IOError

        def failing():
            raise exception_class()

        assert_equal(sentinel,
                     exception_guard(failing, exception_class, sentinel)())
Example #2
0
    def test_returns_sentinel_when_exception_is_raised(self):
        exception_class = IOError

        def failing():
            raise exception_class()

        assert_equal(sentinel,
                     exception_guard(failing, exception_class, sentinel)())
Example #3
0
    def test_does_not_catch_wider_exceptions(self):
        parent_exception = Exception
        child_exception = IOError
        assert_true(issubclass(child_exception, parent_exception))

        def failing():
            raise parent_exception()

        guarded_function = exception_guard(failing, child_exception)
        assert_raises(parent_exception, guarded_function)
Example #4
0
    def test_does_not_catch_wider_exceptions(self):
        parent_exception = Exception
        child_exception = IOError
        assert_true(issubclass(child_exception, parent_exception))

        def failing():
            raise parent_exception()

        guarded_function = exception_guard(failing, child_exception)
        assert_raises(parent_exception, guarded_function)
Example #5
0
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
Example #6
0
 def test_calls_function_when_called(self):
     f = Mock()
     f.return_value = sentinel
     assert_equal(sentinel, exception_guard(f)())
     f.assert_called_once_with()
Example #7
0
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)
Example #8
0
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
Example #9
0
 def test_calls_function_when_called(self):
     f = Mock()
     f.return_value = sentinel
     assert_equal(sentinel, exception_guard(f)())
     f.assert_called_once_with()
Example #10
0
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)