Example #1
0
    def test_connect(self):
        def func():
            pass

        mocksignal = MockSignal()
        hook._registry["foo-hook"] = mocksignal

        hook.connect("foo-hook", func, sender=FakeHook, dispatch_uid="foo")
        self.assertEqual([mocksignal.func, mocksignal.sender, mocksignal.dispatch_uid],
                         [func, FakeHook, "foo"])
Example #2
0
    def test_connect_and_send(self):
        """
        Integration test
        """
        def func_a(signal, sender, **kwargs):
            self._kwargs_a = kwargs

        def func_b(signal, sender, extra, **kwargs):
            self._extra_b = extra

        def func_c(sender, extra, **kwargs):
            self._extra_c = extra

        def func_d(extra, **kwargs):
            # kwargs will contain *sender* and *signal*
            self._extra_d = extra

        hook.connect("foo-hook", func_a, sender=FakeHook)
        hook.connect("foo-hook", func_b, sender=FakeHook)
        hook.connect("foo-hook", func_c, sender=FakeHook)
        hook.connect("foo-hook", func_d, sender=FakeHook)
        hook.send("foo-hook", sender=FakeHook, extra="foobar")
        self.assertDictEqual(self._kwargs_a, {'extra': "foobar", })
        self.assertEqual(self._extra_b, "foobar")
        self.assertEqual(self._extra_c, "foobar")
        self.assertEqual(self._extra_d, "foobar")