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")
def test_send(self): mocksignal = MockSignal() hook._registry["foo-hook"] = mocksignal hook.send("foo-hook", sender=FakeHook, extra="foobar") self.assertEqual([mocksignal.sender, mocksignal.kwargs], [FakeHook, {'extra': "foobar", }])