Ejemplo n.º 1
0
    def test_multiple_for_event(self):
        self.count = 0
        def callback():
            self.count += 1

        bus = EventBus()
        bus.register({"noodle": callback})
        bus.register({"noodle": callback})
        bus.trigger("noodle")
        self.assertEqual(self.count, 2)
Ejemplo n.º 2
0
    def test_multiple_for_event(self):
        self.count = 0

        def callback():
            self.count += 1

        bus = EventBus()
        bus.register({"noodle": callback})
        bus.register({"noodle": callback})
        bus.trigger("noodle")
        self.assertEqual(self.count, 2)
Ejemplo n.º 3
0
    def test_args_passed_through(self):
        self.got_argument = False
        def callback(argument=False):
            self.got_argument = argument

        bus = EventBus()
        bus.register({
            "noodle": callback,
        })
        bus.trigger("noodle", argument=True)
        self.assertTrue(self.got_argument)
Ejemplo n.º 4
0
    def test_single_event(self):
        self.was_fired = False
        def callback():
            self.was_fired = True

        bus = EventBus()
        bus.register({
            "noodle": callback,
        })
        bus.trigger("noodle")
        self.assertTrue(self.was_fired)
Ejemplo n.º 5
0
    def test_args_passed_through(self):
        self.got_argument = False

        def callback(argument=False):
            self.got_argument = argument

        bus = EventBus()
        bus.register({
            "noodle": callback,
        })
        bus.trigger("noodle", argument=True)
        self.assertTrue(self.got_argument)
Ejemplo n.º 6
0
    def test_single_event(self):
        self.was_fired = False

        def callback():
            self.was_fired = True

        bus = EventBus()
        bus.register({
            "noodle": callback,
        })
        bus.trigger("noodle")
        self.assertTrue(self.was_fired)
Ejemplo n.º 7
0
    def test_returned_deferred(self):
        d = Deferred()

        def callback():
            return d

        bus = EventBus()
        bus.register({"noodle": callback})
        trigger_deferred = bus.trigger("noodle")

        self.was_original_deferred_fired_yet = False
        def other_callback(result):
            self.assertTrue(self.was_original_deferred_fired_yet)
        trigger_deferred.addCallback(other_callback)

        self.was_original_deferred_fired_yet = True
        d.callback(None)
Ejemplo n.º 8
0
    def test_returned_deferred(self):
        d = Deferred()

        def callback():
            return d

        bus = EventBus()
        bus.register({"noodle": callback})
        trigger_deferred = bus.trigger("noodle")

        self.was_original_deferred_fired_yet = False

        def other_callback(result):
            self.assertTrue(self.was_original_deferred_fired_yet)

        trigger_deferred.addCallback(other_callback)

        self.was_original_deferred_fired_yet = True
        d.callback(None)