• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pymock.Controller类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sync.ModbusSerialClient类代码示例发布时间:2022-05-27
下一篇:
Python pymisp.PyMISP类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap