Ejemplo n.º 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)())
Ejemplo n.º 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)())
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
Ejemplo n.º 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()
Ejemplo n.º 7
0
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)
Ejemplo n.º 8
0
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
Ejemplo n.º 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()
Ejemplo n.º 10
0
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)