From cfb8edefae94c11b6aaa87043edb129b22c7c6fd Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 13 Jan 2006 16:16:36 +0000 Subject: Add add/remove_emission_hook and tests. Fixes #325977 * gobject/gobjectmodule.c: (pyg_io_add_watch), (marshal_emission_hook), (pyg_add_emission_hook), (pyg_remove_emission_hook): * gobject/pygobject.c: * tests/test_signal.py: Add add/remove_emission_hook and tests. Fixes #325977 --- tests/test_signal.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/test_signal.py') diff --git a/tests/test_signal.py b/tests/test_signal.py index 87c62f6..e9de6e8 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -128,6 +128,45 @@ class TestAccumulator(unittest.TestCase): self.__true_val = 3 return False +class E(gobject.GObject): + __gsignals__ = { 'signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ()) } + def __init__(self): + gobject.GObject.__init__(self) + self.status = 0 + + def do_signal(self): + assert self.status == 0 + self.status = 1 + +class TestEmissionHook(unittest.TestCase): + def testAdd(self): + self.hook = True + e = E() + e.connect('signal', self._callback) + gobject.add_emission_hook(E, "signal", self._emission_hook) + e.emit('signal') + self.assertEqual(e.status, 3) + + def testRemove(self): + self.hook = False + e = E() + e.connect('signal', self._callback) + hook_id = gobject.add_emission_hook(E, "signal", self._emission_hook) + gobject.remove_emission_hook(E, "signal", hook_id) + e.emit('signal') + self.assertEqual(e.status, 3) + + def _emission_hook(self, e): + self.assertEqual(e.status, 1) + e.status = 2 + + def _callback(self, e): + if self.hook: + self.assertEqual(e.status, 2) + else: + self.assertEqual(e.status, 1) + e.status = 3 if __name__ == '__main__': unittest.main() -- cgit