本文整理匯總了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)
示例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, '')() == ''
示例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)()