コード例 #1
0
ファイル: test_utils.py プロジェクト: blin/zabby
    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)())
コード例 #2
0
ファイル: test_utils.py プロジェクト: Bregor/zabby
    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)())
コード例 #3
0
ファイル: test_utils.py プロジェクト: blin/zabby
    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)
コード例 #4
0
ファイル: test_utils.py プロジェクト: Bregor/zabby
    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)
コード例 #5
0
ファイル: test_utils.py プロジェクト: blin/zabby
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
コード例 #6
0
ファイル: test_utils.py プロジェクト: blin/zabby
 def test_calls_function_when_called(self):
     f = Mock()
     f.return_value = sentinel
     assert_equal(sentinel, exception_guard(f)())
     f.assert_called_once_with()
コード例 #7
0
ファイル: test_utils.py プロジェクト: blin/zabby
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)
コード例 #8
0
ファイル: test_utils.py プロジェクト: Bregor/zabby
 def test_passes_arguments(self):
     assert_equal(sentinel, exception_guard(lambda x: x)(sentinel))
コード例 #9
0
ファイル: test_utils.py プロジェクト: Bregor/zabby
 def test_calls_function_when_called(self):
     f = Mock()
     f.return_value = sentinel
     assert_equal(sentinel, exception_guard(f)())
     f.assert_called_once_with()
コード例 #10
0
ファイル: test_utils.py プロジェクト: Bregor/zabby
 def test_returns_a_wrapper(self):
     wrapper = exception_guard(lambda: None)
     assert_is_instance(wrapper, FunctionType)