def test_pass_to_action(self):

        scope = Scope("/lets/go")

        bus = Bus()
        connector = InConnector(bus=bus)
        connector.scope = scope
        connector.activate()

        action = StubSink(scope)
        connector.set_observer_action(action)

        e = Event()
        e.scope = scope
        bus.handle(e)
        assert len(action.events) == 1
        assert e in action.events
Exemple #2
0
    def testPassToAction(self):

        scope = Scope("/lets/go")

        bus = Bus()
        connector = InPushConnector(bus=bus)
        connector.setScope(scope)
        connector.activate()

        action = StubSink(scope)
        connector.setObserverAction(action)

        e = Event()
        e.scope = scope
        bus.handle(e)
        self.assertEqual(1, len(action.events))
        self.assertTrue(e in action.events)
Exemple #3
0
    def testNotifyHierarchy(self):
        bus = Bus()

        targetScope = Scope("/this/is/a/test")
        scopes = targetScope.superScopes(True)
        sinksByScope = {}
        for scope in scopes:
            sinksByScope[scope] = StubSink(scope)
            bus.addSink(sinksByScope[scope])

        notNotifiedSiblingSink = StubSink(Scope("/not/notified"))
        bus.addSink(notNotifiedSiblingSink)
        notNotifiedChildSink = StubSink(targetScope.concat(Scope("/child")))
        bus.addSink(notNotifiedChildSink)

        event = Event(scope=targetScope)
        bus.handle(event)
        for scope, sink in sinksByScope.items():
            self.assertTrue(event in sink.events)
            self.assertEqual(1, len(sink.events))
    def test_notify_hierarchy(self):
        bus = Bus()

        target_scope = Scope("/this/is/a/test")
        scopes = target_scope.super_scopes(True)
        sinks_by_scope = {}
        for scope in scopes:
            sinks_by_scope[scope] = StubSink(scope)
            bus.add_sink(sinks_by_scope[scope])

        not_notified_sibling_sink = StubSink(Scope("/not/notified"))
        bus.add_sink(not_notified_sibling_sink)
        not_notified_child_sink = StubSink(target_scope.concat(
            Scope("/child")))
        bus.add_sink(not_notified_child_sink)

        event = Event(scope=target_scope)
        bus.handle(event)
        for scope, sink in list(sinks_by_scope.items()):
            assert event in sink.events
            assert len(sink.events) == 1