TestEventDispatcher.py
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
import mock
from os.path import dirname, realpath
from sys import argv, path
path.append(dirname(dirname(realpath(__file__))) + '/lib')
from Event.Event import Event
from Event.EventDispatcher import EventDispatcher
class TestEventDisptcher(unittest.TestCase):
def setUp(self):
self._dispatcher = EventDispatcher()
self._handler_mock1 = mock.Mock()
self._handler_mock2 = mock.Mock()
self._handler_mock1.getHandledIds.return_value = [1, 2]
self._handler_mock2.getHandledIds.return_value = [1, 3]
def testRegisterHandler(self):
self._dispatcher.registerHandler(self._handler_mock1)
self._dispatcher.registerHandler(self._handler_mock2)
self._handler_mock1.getHandledIds.called_once()
self._handler_mock2.getHandledIds.called_once()
self._handler_mock1.setDispatcher.called_once()
self._handler_mock2.setDispatcher.called_once()
self.assertIn(1, self._dispatcher._handler)
self.assertIn(2, self._dispatcher._handler)
self.assertIn(3, self._dispatcher._handler)
self.assertNotIn(4, self._dispatcher._handler)
self.assertIn(self._handler_mock1, self._dispatcher._handler[1])
self.assertIn(self._handler_mock2, self._dispatcher._handler[1])
self.assertIn(self._handler_mock1, self._dispatcher._handler[2])
self.assertNotIn(self._handler_mock2, self._dispatcher._handler[2])
self.assertIn(self._handler_mock2, self._dispatcher._handler[3])
def testSetHeartbeat(self):
self._dispatcher.setHeartbeat(None)
self.assertEqual(self._dispatcher._heartbeat, None)
self.assertEqual(self._dispatcher._nextbeat, 0.0)
self._dispatcher.setHeartbeat(1.0)
self.assertEqual(self._dispatcher._heartbeat, 1.0)
self.assertNotEqual(self._dispatcher._nextbeat, 0.0)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestEventDisptcher)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
# vim: set ft=python et ts=8 sw=4 sts=4: