diff options
author | Johan Dahlin <johan@src.gnome.org> | 2006-01-13 16:16:36 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2006-01-13 16:16:36 +0000 |
commit | cfb8edefae94c11b6aaa87043edb129b22c7c6fd (patch) | |
tree | db32c6a7f3de73356bf650bca9d5527109abca60 /tests/test_signal.py | |
parent | e370df75fb2cfdd780188af1e81416a5443cb6e9 (diff) | |
download | pygobject-cfb8edefae94c11b6aaa87043edb129b22c7c6fd.tar.gz pygobject-cfb8edefae94c11b6aaa87043edb129b22c7c6fd.tar.xz pygobject-cfb8edefae94c11b6aaa87043edb129b22c7c6fd.zip |
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
Diffstat (limited to 'tests/test_signal.py')
-rw-r--r-- | tests/test_signal.py | 39 |
1 files changed, 39 insertions, 0 deletions
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() |