Example #1
0
 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)
Example #2
0
    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)
Example #3
0
 def __init__(self):
     super(ExamplePlugin, self).__init__('example')
     self.event_handlers = [
         events.EventHandler(events.EVENT_TICK_1,
                             lambda v: self.log.info("Plugin tick!"))
     ]
Example #4
0
 def get_handlers(self):
     return [events.EventHandler(events.EVENT_TICK_5, self.update)]
Example #5
0
 def __init__(self):
     super(TestPlugin, self).__init__('test')
     self.event_handlers = [
         events.EventHandler(events.EVENT_TICK,
                             lambda v: self.log.info("Plugin tick!"))
     ]