Exemplo n.º 1
0
	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)
Exemplo n.º 2
0
	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)
Exemplo n.º 3
0
	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)
Exemplo n.º 4
0
	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)
Exemplo n.º 5
0
	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
Exemplo n.º 6
0
	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