diff options
Diffstat (limited to 'tests/test_signal.py')
-rw-r--r-- | tests/test_signal.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/test_signal.py b/tests/test_signal.py index 8f31c35..afa9926 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -165,6 +165,9 @@ class E(GObject.GObject): __gsignals__ = {'signal': (GObject.SignalFlags.RUN_FIRST, None, ())} + # Property used to test detailed signal + prop = GObject.Property(type=int, default=0) + def __init__(self): GObject.GObject.__init__(self) self.status = 0 @@ -257,17 +260,66 @@ class TestEmissionHook(unittest.TestCase): class TestClosures(unittest.TestCase): def setUp(self): self.count = 0 + self.emission_stopped = False + self.emission_error = False def _callback(self, e): self.count += 1 - def test_disconnect(self): + def _callback_stop_emission(self, obj, prop, stop_it): + if stop_it: + obj.stop_emission_by_name('notify::prop') + self.emission_stopped = True + else: + self.count += 1 + + def _callback_invalid_stop_emission_name(self, obj, prop): + # We expect a GLib warning but there currently is no way to test that + # This can at least make sure we don't crash + old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL | + GLib.LogLevelFlags.LEVEL_ERROR) + try: + obj.stop_emission_by_name('notasignal::baddetail') + finally: + GLib.log_set_always_fatal(old_mask) + self.emission_error = True + + def test_disconnect_by_func(self): e = E() e.connect('signal', self._callback) e.disconnect_by_func(self._callback) e.emit('signal') self.assertEqual(self.count, 0) + def test_disconnect(self): + e = E() + handler_id = e.connect('signal', self._callback) + self.assertTrue(e.handler_is_connected(handler_id)) + e.disconnect(handler_id) + e.emit('signal') + self.assertEqual(self.count, 0) + self.assertFalse(e.handler_is_connected(handler_id)) + + def test_stop_emission_by_name(self): + e = E() + + # Sandwich a callback that stops emission in between a callback that increments + e.connect('notify::prop', self._callback_stop_emission, False) + e.connect('notify::prop', self._callback_stop_emission, True) + e.connect('notify::prop', self._callback_stop_emission, False) + + e.set_property('prop', 1234) + self.assertEqual(e.get_property('prop'), 1234) + self.assertEqual(self.count, 1) + self.assertTrue(self.emission_stopped) + + def test_stop_emission_by_name_error(self): + e = E() + + e.connect('notify::prop', self._callback_invalid_stop_emission_name) + e.set_property('prop', 1234) + self.assertTrue(self.emission_error) + def test_handler_block(self): e = E() e.connect('signal', self._callback) |