예제 #1
0
 def test_start_and_stop(self):
     app = App('test_start_and_stop', config)
     app.start()
     foo_handler = Handler(foo)
     boo_handler = Handler(boo)
     app.on('show', foo_handler)
     app.on('show', boo_handler, True)
     names = list()
     show_event = Event('show', names=names, name='background')
     app.fire(show_event, False)
     time.sleep(2)
     app.stop()
     self.assertListEqual(names, ['foo-background', 'boo-background'])
예제 #2
0
 def test_start_and_stop(self):
     app = App('test_start_and_stop', config)
     app.start()
     foo_handler = Handler(foo)
     boo_handler = Handler(boo)
     app.on('show', foo_handler)
     app.on('show', boo_handler, True)
     names = list()
     show_event = Event('show', names=names, name='background')
     app.fire(show_event, False)
     time.sleep(2)
     app.stop()
     self.assertListEqual(
         names,
         ['foo-background', 'boo-background'])
예제 #3
0
    def test_allowed_fire(self):
        app = App('test_allowed_fire', config)

        def fire(self, names):
            names.append('fire')
            event = Event('display', names=names, name='B')
            self.fire(event)

        foo_handler = Handler(foo)
        boo_handler = Handler(boo)
        eoo_handler = Handler(eoo)
        fire_handler = Handler(fire, ['display'])
        app.on('show', foo_handler)
        app.on('show', boo_handler, True)
        app.on('show', fire_handler, True)
        app.on('display', eoo_handler)
        names = list()
        show_event = Event('show', names=names, name='A')
        runtime_tree = app.fire(show_event, False)
        self.assertListEqual(names, ['foo-A', 'boo-A', 'fire', 'eoo-B'])
        self.assertEqual(runtime_tree.event_count, 2)
        self.assertEqual(runtime_tree.handler_runtime_count, 4)
        self.assertEqual(runtime_tree.exception_count, 1)
        self.assertNotEqual(runtime_tree.begin_time, None)
        self.assertNotEqual(runtime_tree.end_time, None)
        self.assertNotEqual(runtime_tree.time_cost, -1)
예제 #4
0
 def test_allowed_fire(self):
     app = App('test_allowed_fire', config)
     def fire(self, names):
         names.append('fire')
         event = Event('display', names=names, name='B')
         self.fire(event)
     foo_handler = Handler(foo)
     boo_handler = Handler(boo)
     eoo_handler = Handler(eoo)
     fire_handler = Handler(fire, ['display'])
     app.on('show', foo_handler)
     app.on('show', boo_handler, True)
     app.on('show', fire_handler, True)
     app.on('display', eoo_handler)
     names = list()
     show_event = Event('show', names=names, name='A')
     runtime_tree = app.fire(show_event, False)
     self.assertListEqual(
         names,
         ['foo-A', 'boo-A', 'fire', 'eoo-B'])
     self.assertEqual(runtime_tree.event_count, 2)
     self.assertEqual(runtime_tree.handler_runtime_count, 4)
     self.assertEqual(runtime_tree.exception_count, 1)
     self.assertNotEqual(runtime_tree.begin_time, None)
     self.assertNotEqual(runtime_tree.end_time, None)
     self.assertNotEqual(runtime_tree.time_cost, -1)
예제 #5
0
 def test_save_and_find(self):
     storage = RuntimeTreeStorage(db_path)
     app = App('test_save_and_find')
     foo_handler = Handler(foo)
     app.on('show', foo_handler)
     show_event = Event('show', name='A')
     runtime_tree = app.fire(show_event, False)
     storage.save(runtime_tree)
     self.assertEqual(runtime_tree.dict, storage.find(runtime_tree.id))
예제 #6
0
 def test_save_and_find(self):
     storage = RuntimeTreeStorage(db_path)
     app = App('test_save_and_find')
     foo_handler = Handler(foo)
     app.on('show', foo_handler)
     show_event = Event('show', name='A')
     runtime_tree = app.fire(show_event, False)
     storage.save(runtime_tree)
     self.assertEqual(runtime_tree.dict, storage.find(runtime_tree.id))
예제 #7
0
    def test_pickle(self):
        app = App('test_pickle', config)

        def fire(self):
            names.append('fire')
            event = Event('display', names=names, name='B')
            self.fire(event)

        foo_handler = Handler(foo)
        boo_handler = Handler(boo)
        eoo_handler = Handler(eoo)
        fire_handler = Handler(fire, ['display'])
        app.on('show', foo_handler)
        app.on('show', boo_handler, True)
        app.on('show', fire_handler, True)
        app.on('display', eoo_handler)
        names = list()
        show_event = Event('show', names=names, name='A')
        runtime_tree = app.fire(show_event, False)
        self.assertDictEqual(RuntimeTree.loads(runtime_tree.dumps()),
                             runtime_tree.dict)
예제 #8
0
    def test_handler_decorator(self):
        app = App('test_handler_decorator', config)

        @app.handler('show', ['display'], True)
        def koo(self, names, name):
            names.append('koo-%s' % (name, ))
            event = Event('display', names=names, name='B')
            self.fire(event)

        foo_handler = Handler(foo)
        app.on('display', foo_handler)
        names = list()
        show_event = Event('show', names=names, name='A')
        runtime_tree = app.fire(show_event, False)
        self.assertListEqual(names, ['koo-A', 'foo-B'])
        self.assertEqual(runtime_tree.event_count, 2)
        self.assertEqual(runtime_tree.handler_runtime_count, 2)
        self.assertEqual(runtime_tree.exception_count, 0)
        self.assertNotEqual(runtime_tree.begin_time, None)
        self.assertNotEqual(runtime_tree.end_time, None)
        self.assertNotEqual(runtime_tree.time_cost, -1)
예제 #9
0
 def test_pickle(self):
     app = App('test_pickle', config)
     def fire(self):
         names.append('fire')
         event = Event('display', names=names, name='B')
         self.fire(event)
     foo_handler = Handler(foo)
     boo_handler = Handler(boo)
     eoo_handler = Handler(eoo)
     fire_handler = Handler(fire, ['display'])
     app.on('show', foo_handler)
     app.on('show', boo_handler, True)
     app.on('show', fire_handler, True)
     app.on('display', eoo_handler)
     names = list()
     show_event = Event('show', names=names, name='A')
     runtime_tree = app.fire(show_event, False)
     self.assertDictEqual(
         RuntimeTree.loads(
             runtime_tree.dumps()),
      runtime_tree.dict)
예제 #10
0
 def test_handler_decorator(self):
     app = App('test_handler_decorator', config)
     @app.handler('show', ['display'], True)
     def koo(self, names, name):
         names.append('koo-%s' % (name,))
         event = Event('display', names=names, name='B')
         self.fire(event)
     foo_handler = Handler(foo)
     app.on('display', foo_handler)
     names = list()
     show_event = Event('show', names=names, name='A')
     runtime_tree = app.fire(show_event, False)
     self.assertListEqual(
         names,
         ['koo-A', 'foo-B'])
     self.assertEqual(runtime_tree.event_count, 2)
     self.assertEqual(runtime_tree.handler_runtime_count, 2)
     self.assertEqual(runtime_tree.exception_count, 0)
     self.assertNotEqual(runtime_tree.begin_time, None)
     self.assertNotEqual(runtime_tree.end_time, None)
     self.assertNotEqual(runtime_tree.time_cost, -1)