本文整理汇总了Python中pymock.Controller类的典型用法代码示例。如果您正苦于以下问题:Python Controller类的具体用法?Python Controller怎么用?Python Controller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Controller类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:agilist,项目名称:springmemo,代码行数:7,代码来源:test_pymock.py
示例2: testSettingClassMethod
def testSettingClassMethod(self):
c = Controller()
class MethodTarget(object):
def m(self):
pass
mt = MethodTarget()
c.override(mt, 'm', lambda(x): x)
开发者ID:agilist,项目名称:springmemo,代码行数:7,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:8,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:8,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:8,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:9,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:9,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:9,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:10,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:10,代码来源:test_pymock.py
示例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)
开发者ID:agilist,项目名称:springmemo,代码行数:11,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:11,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:12,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:12,代码来源:test_pymock.py
示例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
开发者ID:agilist,项目名称:springmemo,代码行数:12,代码来源:test_pymock.py
示例16: testExplicitGeneratorExecptionUsage
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)
开发者ID:agilist,项目名称:springmemo,代码行数:12,代码来源:test_pymock.py
示例17: testOverrideOfTwoItems
def testOverrideOfTwoItems(self):
"""Verify override stores and replays for multiple items"""
c = Controller()
x = KlassBeingMocked()
y = KlassBeingMocked()
x.f = 38
y.g = 39
c.override(x, 'f', 5)
c.override(y, 'g', 6)
self.failUnless(x.f == 5)
self.failUnless(y.g == 6)
c.restore()
self.failUnless(x.f == 38)
self.failUnless(y.g == 39)
开发者ID:agilist,项目名称:springmemo,代码行数:14,代码来源:test_pymock.py
示例18: testObjectWithProxiedClass
def testObjectWithProxiedClass(self):
c = Controller()
class ClassToClone(object):
def m(self):
pass
x = ClassToClone()
y = ClassToClone()
c.attachObjectToProxyClass(y)
y.__class__.f = lambda x: None
try:
x.f()
self.fail()
except AttributeError, e:
pass
开发者ID:agilist,项目名称:springmemo,代码行数:14,代码来源:test_pymock.py
示例19: testProxyClassForObject
def testProxyClassForObject(self):
c = Controller()
class ClassToClone(object):
def m(self):
pass
x = ClassToClone()
ClonedClass = c.proxyClassForObject(x)
ClonedClass.f = ClonedClass.m
y = ClonedClass()
x.m()
try:
x.f()
self.fail()
except AttributeError, e:
pass
开发者ID:agilist,项目名称:springmemo,代码行数:15,代码来源:test_pymock.py
示例20: testExpectAndReturn
def testExpectAndReturn(self):
"""Check expect and return"""
c = Controller()
x = c.mock()
c.expectAndReturn(x.g(8, 9), 5)
c.replay()
self.failUnless(x.g(8, 9) == 5)
c.verify()
开发者ID:agilist,项目名称:springmemo,代码行数:8,代码来源:test_pymock.py
注:本文中的pymock.Controller类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论