aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/event_loop_call_virtual_test.py
blob: 90f0ac6c8aaa8416bc3b1fccfef33d455caafd93 (plain)
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
#!/usr/bin/env python


'''Simple event loop dispatcher test.'''

import time
import unittest
from random import random

from sample import ObjectType, Event


class NoOverride(ObjectType):

    pass


class Override(ObjectType):

    def __init__(self):
        ObjectType.__init__(self)
        self.called = False

    def event(self, event):
        self.called = True
        return True


class TestEventLoop(unittest.TestCase):

    def testEventLoop(self):
        '''Calling virtuals in a event loop'''
        objs = [ObjectType(), NoOverride(), Override()]

        evaluated = ObjectType.processEvent(objs,
                                        Event(Event.BASIC_EVENT))

        self.assertEqual(evaluated, 3)
        self.assert_(objs[2].called)


if __name__ == '__main__':
    unittest.main()