5 from gi.repository import GLib
9 def __init__(self, loop):
10 GLib.Idle.__init__(self)
12 self.set_callback(self.callback, loop)
14 def callback(self, loop):
19 class MySource(GLib.Source):
21 GLib.Source.__init__(self)
29 def dispatch(self, callback, args):
30 return callback(*args)
33 class TestSource(unittest.TestCase):
34 def timeout_callback(self, loop):
37 def my_callback(self, loop):
41 def setup_timeout(self, loop):
42 timeout = GLib.Timeout(500)
43 timeout.set_callback(self.timeout_callback, loop)
46 def testSources(self):
47 loop = GLib.MainLoop()
49 self.setup_timeout(loop)
57 m.set_callback(self.my_callback, loop)
62 assert self.pos >= 0 and idle.count >= 0
64 def testSourcePrepare(self):
65 # this test may not terminate if prepare() is wrapped incorrectly
67 loop = GLib.MainLoop()
69 class CustomTimeout(GLib.Source):
76 def dispatch(self, callback, args):
83 source = CustomTimeout()
86 source.set_callback(dir)
92 def testIsDestroyedSimple(self):
95 self.assertFalse(s.is_destroyed())
97 self.assertTrue(s.is_destroyed())
99 c = GLib.MainContext()
102 self.assertFalse(s.is_destroyed())
104 self.assertTrue(s.is_destroyed())
106 def testIsDestroyedContext(self):
108 c = GLib.MainContext()
114 self.assertTrue(s.is_destroyed())
117 class TestTimeout(unittest.TestCase):
118 def test504337(self):
123 if __name__ == '__main__':