本文整理汇总了Python中pymock.Controller类的典型用法代码示例。如果您正苦于以下问题:Python Controller类的具体用法?Python Controller怎么用?Python Controller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Controller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRecord
def testRecord(self):
"""Verify recording of a new action"""
c = Controller()
action = BaseAction('x')
c.record(action)
self.failUnless(c.actions.contains(action))
self.failUnless(c.actionUnderConstruction == action)
示例2: testSettingClassMethod
def testSettingClassMethod(self):
c = Controller()
class MethodTarget(object):
def m(self):
pass
mt = MethodTarget()
c.override(mt, 'm', lambda(x): x)
示例3: testPlayModeAndSwitches
def testPlayModeAndSwitches(self):
"""Verify that the replay switch works"""
c = Controller()
self.failUnless(c.isRecording)
self.failIf(c.isPlayingBack)
c.replay()
self.failIf(c.isRecording)
self.failUnless(c.isPlayingBack)
示例4: testSetCount
def testSetCount(self):
"""Verify that settting the count works"""
c = Controller()
a = BaseAction('x')
c.record(a)
self.failUnless(a.playbackPolicy.remaining == 1)
c.setCount(2)
self.failUnless(a.playbackPolicy.remaining == 2)
示例5: testUnusedAttributeAssignmentCanBeVerified
def testUnusedAttributeAssignmentCanBeVerified(self):
"""Ensure that unused calls cause verification failure"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
c.replay()
self.failUnlessRaises(RecordedCallsWereNotReplayedCorrectly, c.verify)
示例6: testPlayback
def testPlayback(self):
"""Ensure that the playback operates correctly"""
c = Controller()
action = BaseAction('x')
c.actions.append(action)
c.playback(action)
self.failIf(c.actions.contains(action))
self.failUnless(action.playbackPolicy.hasBeenPlayedBack)
self.failUnless(action.playbackPolicy.isReadyForRemoval)
示例7: testOverrideOfOneItem
def testOverrideOfOneItem(self):
"""Verify override stores and replays"""
c = Controller()
x = KlassBeingMocked()
x.f = 38
c.override(x, 'f', 5)
self.failUnless(x.f == 5)
c.restore()
self.failUnless(x.f == 38)
示例8: testAttributeAssignmentCanBePlayedBack
def testAttributeAssignmentCanBePlayedBack(self):
"""Attibute assignment should be intercepted"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
x.w = 6
c.replay()
x.w = 5
示例9: testUndefinedPlaybackRaisesException
def testUndefinedPlaybackRaisesException(self):
"""Playback failure should raise an exception"""
c = Controller()
x = c.mock(KlassBeingMocked)
c.replay()
try:
x.w = 5
self.fail()
except PlaybackFailure, e:
pass
示例10: testSetAttributeRecordsField
def testSetAttributeRecordsField(self):
"""Ensure setting an attribute is correctly recorded"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
self.failUnless(len(c.actions) == 1)
action = c.actions.get(BaseAction((x,'w')))
self.failUnless(action.field == 'w')
self.failUnless(action.value == 5)
示例11: testFunctionCallWithMismatchedArguments
def testFunctionCallWithMismatchedArguments(self):
"""Function call with mismatched arguments"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.g(3, 4)
x.h()
x.i(8, v1=4, v2=3)
c.replay()
self.failUnlessRaises(PlaybackFailure, x.g, 5, 3)
self.failUnlessRaises(PlaybackFailure, x.h, 2)
self.failUnlessRaises(PlaybackFailure, x.i, 8, v1=4, v2=5)
示例12: testSetCountOneOrMoreRaisesErrorOnNextRecord
def testSetCountOneOrMoreRaisesErrorOnNextRecord(self):
"""Setting an unlimited count causes subsequent records to fail"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
c.oneOrMore()
try:
x.w = 6
self.fail()
except IllegalPlaybackRecorded, e:
pass
示例13: testGetattrWithNoReturnValueSpecified
def testGetattrWithNoReturnValueSpecified(self):
"""Getattr with no return value specified"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.g
c.replay()
self.failIf(x.g == None)
try:
x.g
self.fail()
except PlaybackFailure, e:
pass
示例14: testAttributeAssignmentIsIntercepted
def testAttributeAssignmentIsIntercepted(self):
"""Attibute assignment should be intercepted"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
c.replay()
try:
x.w
self.fail()
except PlaybackFailure, e:
pass
示例15: testPlaybackFailsWithIncorrectValues
def testPlaybackFailsWithIncorrectValues(self):
"""Ensure playing back incorrect values results in an error"""
c = Controller()
x = c.mock(KlassBeingMocked)
x.w = 5
c.replay()
try:
x.w = 4
self.fail()
except PlaybackFailure, e:
pass