5 from gi.repository import GLib
8 def __init__(self, loop):
9 GLib.Idle.__init__(self)
11 self.set_callback(self.callback, loop)
13 def callback(self, loop):
18 class MySource(GLib.Source):
20 GLib.Source.__init__(self)
28 def dispatch(self, callback, args):
29 return callback(*args)
32 class TestSource(unittest.TestCase):
33 def timeout_callback(self, loop):
36 def my_callback(self, loop):
40 def setup_timeout(self, loop):
41 timeout = GLib.Timeout(500)
42 timeout.set_callback(self.timeout_callback, loop)
45 def testSources(self):
46 loop = GLib.MainLoop()
48 self.setup_timeout(loop)
56 m.set_callback(self.my_callback, loop)
61 assert self.pos >= 0 and idle.count >= 0
63 def testSourcePrepare(self):
64 # this test may not terminate if prepare() is wrapped incorrectly
66 loop = GLib.MainLoop()
68 class CustomTimeout(GLib.Source):
75 def dispatch(self, callback, args):
82 source = CustomTimeout()
85 source.set_callback(dir)
92 class TestTimeout(unittest.TestCase):
94 timeout_source = GLib.Timeout(20)
95 idle_source = GLib.Idle()
98 if __name__ == '__main__':