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