예제 #1
0
 def test_execute_with_params(self):
     ReaderHandler().execute(book_name=12)
     ReaderHandler().execute(second=12)
     SleepHandler().execute(second=0.01)
     SleepHandler().execute(second=-0.01)
     SleepHandler().execute(second='fds')
     AuthorHandler().execute(book_name=12)
     AuthorHandler().execute(second=12)
예제 #2
0
def main():
    # 注册一般没有参数
    EventEngine().register(EVENT_WRITE_BOOK,
                           AuthorHandler(), ReaderHandler(), SleepHandler()
                           )
    EventEngine().register(EVENT_READ_BOOK, ReaderHandler(), SleepHandler())

    EventEngine().send(EVENT_WRITE_BOOK, delay=0.1, book_name='book1', second=0.4)
    EventEngine().send(EVENT_WRITE_BOOK, delay=0.4, book_name='book2')
    EventEngine().send(EVENT_READ_BOOK, delay=0, book_name='book3', second=0.6)
    EventEngine().send(EVENT_READ_BOOK, delay=0.1, book_name='book4')
예제 #3
0
 def test_callback(self):
     ReaderHandler().callback(second=0.01)
     AuthorHandler().callback(second=0.01)
     try:
         SleepHandler().callback(second=0.01)
     except AttributeError:
         pass
예제 #4
0
    def test_register(self):
        try:
            self.engine.register('event')
        except Exception as e:
            assert e.__str__() == '__add_handlers without handlers'

        try:
            self.engine.register('event', 78)
        except AttributeError as e:
            assert e.__str__() == '78 is not from BaseHandler'

        self.engine.register('event', ReaderHandler(), ReaderHandler())

        try:
            self.engine.register('event', ReaderHandler())
        except Exception as e:
            assert e.__str__() == 'event_name:event exist'
예제 #5
0
 def setUp(self):
     super().setUp()
     self._handler = ReaderHandler()
     self._queue = EventQueue()
     self._consumer = EventConsumer(self._queue)
     self._delay = 0.1
예제 #6
0
 def setUp(self):
     super().setUp()
     self._handler = ReaderHandler()
     self._delay = 1
예제 #7
0
 def test_execute(self):
     ReaderHandler().execute()
     SleepHandler().execute()
     AuthorHandler().execute()