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
    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