本文整理汇总了Python中sure.old.AssertionHelper.raises方法的典型用法代码示例。如果您正苦于以下问题:Python AssertionHelper.raises方法的具体用法?Python AssertionHelper.raises怎么用?Python AssertionHelper.raises使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sure.old.AssertionHelper
的用法示例。
在下文中一共展示了AssertionHelper.raises方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: throw
# 需要导入模块: from sure.old import AssertionHelper [as 别名]
# 或者: from sure.old.AssertionHelper import raises [as 别名]
def throw(self, *args, **kw):
_that = AssertionHelper(self.obj, with_args=self._callable_args, and_kwargs=self._callable_kw)
if self.negative:
msg = "{0} called with args {1} and kwargs {2} should " "not raise {3} but raised {4}"
exc = args and args[0] or Exception
try:
self.obj(*self._callable_args, **self._callable_kw)
return True
except Exception as e:
err = msg.format(self.obj, self._that._callable_args, self._that._callable_kw, exc, e)
raise AssertionError(err)
return _that.raises(*args, **kw)
示例2: cool
# 需要导入模块: from sure.old import AssertionHelper [as 别名]
# 或者: from sure.old.AssertionHelper import raises [as 别名]
def cool(self):
_that = AssertionHelper(self.obj,
with_args=self._callable_args,
and_kwargs=self._callable_kw)
if self.negative:
try:
return _that.raises(Exception)
except AssertionError:
raise AssertionError('The callable `{0}` was supposed to not be cool and throw an exception, but it is too cool for that'.format(self.obj.__name__))
try:
self.obj(*self._callable_args, **self._callable_kw)
except Exception as e:
raise AssertionError('The callable `{2}` should be cool but threw {0}: {1}'.format(
e.__class__.__name__,
str(e),
self.obj.__name__
))
return True