def setUp(self): self.event_1 = events.EventHandler(events.EVENT_TORRENT_COMPLETE, e_func, priority=1) self.event_2 = events.EventHandler(events.EVENT_TORRENT_COMPLETE, e_func_2, priority=1)
def test_event_emit(self): em = events.EventManager() em.register_handler(self.event_1) em.register_handler(self.event_2) resp = em.emit(Event(self.event_1.event, {'a': 1}), immediate=True) self.assertEqual(resp['a'], 4) class A(object): def __init__(self, a=1): self.a = a def __call__(self, *args, **kwargs): self.a += 1 incr = A() e = events.EventHandler('test', incr, priority=1) em.register_handler(e) em.emit(Event('test', {'a': 1}), immediate=False) # wait for executor to run the task gevent.sleep(0.1) self.assertEqual(incr.a, 2)
def __init__(self): super(ExamplePlugin, self).__init__('example') self.event_handlers = [ events.EventHandler(events.EVENT_TICK_1, lambda v: self.log.info("Plugin tick!")) ]
def get_handlers(self): return [events.EventHandler(events.EVENT_TICK_5, self.update)]
def __init__(self): super(TestPlugin, self).__init__('test') self.event_handlers = [ events.EventHandler(events.EVENT_TICK, lambda v: self.log.info("Plugin tick!")) ]