예제 #1
0
	def setUp(self):
		self.eventemitter = EventEmitter()
		self._method_calls = []
예제 #2
0
class EventEmitterTest(unittest.TestCase):
	def setUp(self):
		self.eventemitter = EventEmitter()
		self._method_calls = []

	def _method(self, *args, **kwds):
		self._method_calls.append((args, kwds))

	def _exception_method(self, *args, **kwds):
		raise ValueError("error")

	def testOn(self):
		self.eventemitter.on('test', self._method)
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [(("This is a test",), {})])

	def testCallbackFailure(self):
		self.eventemitter.on('test', self._exception_method)
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [])

	def testOff(self):
		self.eventemitter.on('test', self._method)
		self.eventemitter.off('test', self._method)
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [])

	def testOnce(self):
		self.eventemitter.once('test', self._method)
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [(("This is a test",), {})])
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [(("This is a test",), {})])

	def testCLear(self):
		self.eventemitter.on('test', self._method)
		self.eventemitter.clear()
		self.eventemitter.emit('test', "This is a test")
		self.assertEqual(self._method_calls, [])