本文整理汇总了Python中pymock.Controller.setException方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.setException方法的具体用法?Python Controller.setException怎么用?Python Controller.setException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymock.Controller
的用法示例。
在下文中一共展示了Controller.setException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExceptionRaisedByFunctions
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testExceptionRaisedByFunctions(self):
"""Ensure that function calls play back exceptions"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.g.h(3, 4)
c.setException(Exception)
c.replay()
self.failUnlessRaises(Exception, x.g.h, 3, 4)
示例2: testIterDoesNotAllowRecordingAfterAnException
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testIterDoesNotAllowRecordingAfterAnException(self):
"""Ensure that __iter__ records and replays exceptions"""
c = Controller()
x = c.mock()
x.__iter__()
c.setReturn(1)
c.setException(Exception)
self.failUnlessRaises(Exception, c.setReturn, 2)
self.failUnlessRaises(Exception, c.setException, Exception)
示例3: testIterWithException
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testIterWithException(self):
"""Ensure that __iter__ records and replays exceptions"""
c = Controller()
x = c.mock()
x.__iter__()
c.setReturn(1)
c.setException(Exception)
c.replay()
i = x.__iter__()
self.failUnless(i.next() == 1)
self.failUnlessRaises(Exception, i.next)
示例4: testExplicitGeneratorExecptionUsage
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testExplicitGeneratorExecptionUsage(self):
"""Check exception raising with explicit generators using discrete settings"""
c = Controller()
x = c.mock()
x.g(8, 9)
c.generator()
c.setReturn(10)
c.setException(Exception("bogus"))
c.replay()
g = x.g(8, 9)
self.failUnless(g.next() == 10)
self.failUnlessRaises(Exception, g.next)
示例5: testExceptionRaisedBySetattr
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testExceptionRaisedBySetattr(self):
"""Ensure that setattr returns function calls"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.g = 6
c.setException(Exception)
c.replay()
try:
x.g = 6
self.fail()
except Exception, e:
pass
示例6: testExceptionRaisedByGetattr
# 需要导入模块: from pymock import Controller [as 别名]
# 或者: from pymock.Controller import setException [as 别名]
def testExceptionRaisedByGetattr(self):
"""Ensure that getattr plays back exceptions"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.g
c.setException(Exception)
c.replay()
try:
x.g
self.fail()
except Exception, e:
pass