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
예제 #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)
    def test_handle(self):

        bus = Bus()
        connector = OutConnector(bus=bus)

        scope = Scope("/a/test")
        sink = StubSink(scope)
        bus.add_sink(sink)

        e = Event()
        e.scope = scope

        before = time.time()
        connector.handle(e)
        after = time.time()
        assert len(sink.events) == 1
        assert e in sink.events
        assert e.meta_data.send_time >= before
        assert e.meta_data.send_time <= after
예제 #4
0
    def testHandle(self):

        bus = Bus()
        connector = OutConnector(bus=bus)

        scope = Scope("/a/test")
        sink = StubSink(scope)
        bus.addSink(sink)

        e = Event()
        e.scope = scope

        before = time.time()
        connector.handle(e)
        after = time.time()
        self.assertEqual(1, len(sink.events))
        self.assertTrue(e in sink.events)
        self.assertTrue(e.metaData.sendTime >= before)
        self.assertTrue(e.metaData.sendTime <= after)
예제 #5
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
 def test_construction(self):
     Bus()
예제 #8
0
 def testConstruction(self):
     Bus()