當前位置: 首頁>>代碼示例>>Python>>正文


Python Utils.exception_wrapper方法代碼示例

本文整理匯總了Python中Cerebrum.Utils.exception_wrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python Utils.exception_wrapper方法的具體用法?Python Utils.exception_wrapper怎麽用?Python Utils.exception_wrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cerebrum.Utils的用法示例。


在下文中一共展示了Utils.exception_wrapper方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: wrapper

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import exception_wrapper [as 別名]
 def wrapper(self, *rest, **kw_args):
     # This gives us a wrapped method that ignores the suitable
     # exceptions ...
     func = Utils.exception_wrapper(functor, exc_list, return_on_exc,
                                    self.logger)
     # ... and here we call the wrapped method.
     return func(self, *rest, **kw_args)
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:9,代碼來源:xml2object.py

示例2: test_exception_wrapper_behaviour

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import exception_wrapper [as 別名]
def test_exception_wrapper_behaviour():
    """ Utils.exception_wrapper with valid arguments. """
    # Ignoring all exceptions with defaults always yields None
    assert Utils.exception_wrapper(noop, None)() is None
    # Ignoring the exception raised with defaults always yields None
    assert Utils.exception_wrapper(raise1, ValueError)() is None
    # Exceptions can be given as tuples ...
    assert Utils.exception_wrapper(raise1, (ValueError,))() is None
    # ... lists
    assert Utils.exception_wrapper(raise1, [ValueError, ])() is None
    # ... or sets without affecting the result
    assert Utils.exception_wrapper(raise1, set((ValueError,)))() is None

    # Exception not matching the spec are not caught
    nose.tools.assert_raises(ValueError,
                             Utils.exception_wrapper(raise1, AttributeError))

    # Return value with no exceptions is not altered
    assert Utils.exception_wrapper(noop, None, '')() is None
    # Return value with exceptions matches the arg
    assert Utils.exception_wrapper(raise1, ValueError, '')() == ''
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:23,代碼來源:test_core_Utils.py

示例3: test_exception_wrapper_returns_callable

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import exception_wrapper [as 別名]
def test_exception_wrapper_returns_callable():
    """ Utils.exception_wrapper returns callable. """
    assert hasattr(Utils.exception_wrapper(noop), '__call__')
    Utils.exception_wrapper(noop)()
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:6,代碼來源:test_core_Utils.py


注:本文中的Cerebrum.Utils.exception_wrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。