Exemplo n.º 1
0
 def test_setup(self):
     e2e = EventToEvent({'abc': 'def'})
     event_manager = EventManager()
     self.assertEqual(event_manager.get('abc').getSubscriberCount(), 0)
     e2e.setup(event_manager)
     self.assertEqual(e2e.event_manager, event_manager)
     self.assertEqual(event_manager.get('abc').getSubscriberCount(), 1)
Exemplo n.º 2
0
 def test_update_progress(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'AA',
             'delay': 30,
             'target': 'BB'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     self.assertEqual(delay_events._delay_items[0].timer, 30)
     delay_events.update(10)  # let 10 seconds 'pass'
     self.assertEqual(delay_events._delay_items[0].timer, 20)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
     delay_events.update(10)  # let another 10 seconds 'pass'
     self.assertEqual(delay_events._delay_items[0].timer, 10)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
     delay_events.update(
         10)  # let 10 seconds again, reaching 30 second mark
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1)
Exemplo n.º 3
0
 def test_start_after_halt(self):
     delay_events = DelayEvents({
         'example': {
             'source': 'loop',
             'delay': 10,
             'target': 'loop',
             'halt': 'halter'
         }
     })
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # start
     event_manager.get('loop').fire()
     # reach first loop (2nd loop fire)
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # stop
     event_manager.get('halter').fire()
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # start again
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # finish another cycle since starting again
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 4)
Exemplo n.º 4
0
 def test_setup(self):
     e2e = EventToEvent({'abc': 'def'})
     event_manager = EventManager()
     self.assertEqual(event_manager.get('abc').getSubscriberCount(), 0)
     e2e.setup(event_manager)
     self.assertEqual(e2e.event_manager, event_manager)
     self.assertEqual(event_manager.get('abc').getSubscriberCount(), 1)
Exemplo n.º 5
0
 def test_setup(self):
     delay_events = DelayEvents({'example': {'source': 'loop', 'delay': 60, 'target': 'loop'}})
     event_manager = EventManager()
     self.assertEqual(event_manager.get('loop').getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events.event_manager, event_manager)
     self.assertEqual(event_manager.get('loop').getSubscriberCount(), 1)
Exemplo n.º 6
0
 def test_get_returns_none_for_non_existing_events(self):
     em = EventManager()
     event1 = em.get('bar')
     event2 = em.get('foo', create=False)
     event3 = em.get('bar', create=False)
     self.assertIsNone(event2)
     self.assertEqual(event1, event3)
Exemplo n.º 7
0
 def test_get_returns_none_for_non_existing_events(self):
     em = EventManager()
     event1 = em.get('bar')
     event2 = em.get('foo', create=False)
     event3 = em.get('bar', create=False)
     self.assertIsNone(event2)
     self.assertEqual(event1, event3)
Exemplo n.º 8
0
 def test_update_with_trigger(self):
     delay_events = DelayEvents({'example': {'source': 'AA', 'delay': 50, 'target': 'BB'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     delay_events.update(50) # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1)
Exemplo n.º 9
0
 def test_input_event_play(self):
     omxvideo = OmxVideo({'input_events': {'play_event': 'play'}})
     em = EventManager()
     self.assertEqual(len(em.get('play_event')), 0) # no yet registered
     omxvideo.setup(em)
     self.assertEqual(len(em.get('play_event')), 1) # registered
     self.assertEqual(omxvideo.playEvent._fireCount, 0) # not fire
     omxvideo.event_manager.fire('play_event')
     self.assertEqual(omxvideo.playEvent._fireCount, 1) # fired
     omxvideo.destroy()
     self.assertEqual(len(em.get('play_event')), 0) # unregistered
Exemplo n.º 10
0
 def test_input_event_stop(self):
     omxvideo = OmxVideo({'input_events': {'stop_event': 'stop'}})
     em = EventManager()
     self.assertEqual(len(em.get('stop_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('stop_event')), 1) # registered
     self.assertEqual(omxvideo.stopEvent._fireCount, 0)
     omxvideo.event_manager.fire('stop_event')
     self.assertEqual(omxvideo.stopEvent._fireCount, 1)
     omxvideo.destroy()
     self.assertEqual(len(em.get('stop_event')), 0) # unregistered
Exemplo n.º 11
0
    def test_multiple_input_events(self):
        input_events = {
            'play_event1': 'play',
            'play_event2': 'play',
            'pause_event1': 'pause',
            'pause_event2': 'pause',
            'toggle_event1': 'toggle',
            'toggle_event2': 'toggle',
            'stop_event1': 'stop',
            'stop_event2': 'stop',
            'load_event1': 'load',
            'load_event2': 'load',
            'start_event1': 'start',
            'start_event2': 'start',
            'seek_event1': 'seek',
            'seek_event2': 'seek'
        }

        omxvideo = OmxVideo({'input_events': input_events, 'playlist': ['1']})
        em = EventManager()

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 0)  # not yet registered

        omxvideo.setup(em)

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 1)  # registered

        self.assertEqual(omxvideo.playEvent._fireCount, 0)
        self.assertEqual(omxvideo.pauseEvent._fireCount, 0)
        self.assertEqual(omxvideo.toggleEvent._fireCount, 0)
        self.assertEqual(omxvideo.stopEvent._fireCount, 0)
        self.assertEqual(omxvideo.startEvent._fireCount, 0)
        self.assertEqual(omxvideo.loadEvent._fireCount, 0)
        self.assertEqual(omxvideo.seekEvent._fireCount, 0)

        for name in input_events.keys():
            omxvideo.event_manager.fire(name)

        self.assertEqual(omxvideo.playEvent._fireCount,
                         4)  # the two 'start' actions also call play
        self.assertEqual(omxvideo.pauseEvent._fireCount, 2)
        self.assertEqual(omxvideo.toggleEvent._fireCount, 2)
        self.assertEqual(omxvideo.stopEvent._fireCount, 2)
        self.assertEqual(omxvideo.startEvent._fireCount, 2)
        self.assertEqual(omxvideo.loadEvent._fireCount,
                         4)  # the two start actions also load
        self.assertEqual(omxvideo.seekEvent._fireCount, 2)

        omxvideo.destroy()

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 0)  # unregistered
Exemplo n.º 12
0
 def test_input_event_stop(self):
     omxvideo = OmxVideo({'input_events': {'stop_event': 'stop'}})
     em = EventManager()
     self.assertEqual(len(em.get('stop_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('stop_event')), 1)  # registered
     self.assertEqual(omxvideo.stopEvent._fireCount, 0)
     omxvideo.event_manager.fire('stop_event')
     self.assertEqual(omxvideo.stopEvent._fireCount, 1)
     omxvideo.destroy()
     self.assertEqual(len(em.get('stop_event')), 0)  # unregistered
Exemplo n.º 13
0
 def test_input_event_play(self):
     omxvideo = OmxVideo({'input_events': {'play_event': 'play'}})
     em = EventManager()
     self.assertEqual(len(em.get('play_event')), 0)  # no yet registered
     omxvideo.setup(em)
     self.assertEqual(len(em.get('play_event')), 1)  # registered
     self.assertEqual(omxvideo.playEvent._fireCount, 0)  # not fire
     omxvideo.event_manager.fire('play_event')
     self.assertEqual(omxvideo.playEvent._fireCount, 1)  # fired
     omxvideo.destroy()
     self.assertEqual(len(em.get('play_event')), 0)  # unregistered
Exemplo n.º 14
0
 def test_setup(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'loop',
             'delay': 60,
             'target': 'loop'
         }})
     event_manager = EventManager()
     self.assertEqual(event_manager.get('loop').getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events.event_manager, event_manager)
     self.assertEqual(event_manager.get('loop').getSubscriberCount(), 1)
Exemplo n.º 15
0
 def test_expired_delay(self):
     delay_events = DelayEvents({'example': {'source': 'AA', 'delay': 10, 'target': 'BB'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     delay_events.update(10) # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1) # B got fired
     delay_events.update(10) # let's move another 10 seconds into the future
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1) # B didn't get fired again
Exemplo n.º 16
0
    def test_multiple_input_events(self):
        input_events = {
            'play_event1': 'play',
            'play_event2': 'play',
            'pause_event1': 'pause',
            'pause_event2': 'pause',
            'toggle_event1': 'toggle',
            'toggle_event2': 'toggle',
            'stop_event1': 'stop',
            'stop_event2': 'stop',
            'load_event1': 'load',
            'load_event2': 'load',
            'start_event1': 'start',
            'start_event2': 'start',
            'seek_event1': 'seek',
            'seek_event2': 'seek'
        }

        omxvideo = OmxVideo({'input_events': input_events, 'playlist': ['1']})
        em = EventManager()

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 0) # not yet registered

        omxvideo.setup(em)

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 1) # registered

        self.assertEqual(omxvideo.playEvent._fireCount, 0)
        self.assertEqual(omxvideo.pauseEvent._fireCount, 0)
        self.assertEqual(omxvideo.toggleEvent._fireCount, 0)
        self.assertEqual(omxvideo.stopEvent._fireCount, 0)
        self.assertEqual(omxvideo.startEvent._fireCount, 0)
        self.assertEqual(omxvideo.loadEvent._fireCount, 0)
        self.assertEqual(omxvideo.seekEvent._fireCount, 0)

        for name in input_events.keys():
            omxvideo.event_manager.fire(name)

        self.assertEqual(omxvideo.playEvent._fireCount, 4) # the two 'start' actions also call play
        self.assertEqual(omxvideo.pauseEvent._fireCount, 2)
        self.assertEqual(omxvideo.toggleEvent._fireCount, 2)
        self.assertEqual(omxvideo.stopEvent._fireCount, 2)
        self.assertEqual(omxvideo.startEvent._fireCount, 2)
        self.assertEqual(omxvideo.loadEvent._fireCount, 4) # the two start actions also load
        self.assertEqual(omxvideo.seekEvent._fireCount, 2)

        omxvideo.destroy()

        for name in input_events.keys():
            self.assertEqual(len(em.get(name)), 0) # unregistered
Exemplo n.º 17
0
 def test_input_event_start(self):
     omxvideo = OmxVideo({'input_events': {'start_event': 'start'}})
     em = EventManager()
     self.assertEqual(len(em.get('start_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('start_event')), 1) # registered
     self.assertEqual(omxvideo.startEvent._fireCount, 0)
     omxvideo.event_manager.fire('start_event') # fire without params
     self.assertEqual(omxvideo.startEvent._fireCount, 1) # performed
     omxvideo.event_manager.get('start_event').fire(3) # fire with number param
     self.assertEqual(omxvideo.startEvent._fireCount, 2) # performed again
     omxvideo.destroy()
     self.assertEqual(len(em.get('start_event')), 0) # unregistered
Exemplo n.º 18
0
 def test_input_event_load(self):
     omxvideo = OmxVideo({'input_events': {'load_event': 'load'}, 'playlist': ['1', '2', '3', '4']})
     em = EventManager()
     self.assertEqual(len(em.get('load_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('load_event')), 1) # registered
     self.assertEqual(omxvideo.loadEvent._fireCount, 0)
     omxvideo.event_manager.fire('load_event') # fire without params
     self.assertEqual(omxvideo.loadEvent._fireCount, 1) # performed
     omxvideo.event_manager.get('load_event').fire(3) # fire with number param
     self.assertEqual(omxvideo.loadEvent._fireCount, 2) # performed again
     omxvideo.destroy()
     self.assertEqual(len(em.get('load_event')), 0) # unregistered
Exemplo n.º 19
0
 def test_update(self):
     sine = Sine({'output_events': {'value': 'newSineValue'}})
     em = EventManager()
     self.assertIsNone(em.get('newSineValue', create=False))
     sine.setup(em)
     self.assertIsNotNone(em.get('newSineValue', create=False))
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 1)
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 2)
     sine.update()
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 4)
Exemplo n.º 20
0
 def test_update(self):
     sine = Sine({'output_events': {'value': 'newSineValue'}})
     em = EventManager()
     self.assertIsNone(em.get('newSineValue', create=False))
     sine.setup(em)
     self.assertIsNotNone(em.get('newSineValue', create=False))
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 1)
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 2)
     sine.update()
     sine.update()
     self.assertEqual(em.get('newSineValue')._fireCount, 4)
Exemplo n.º 21
0
 def test_update_with_trigger(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'AA',
             'delay': 50,
             'target': 'BB'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     delay_events.update(50)  # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1)
Exemplo n.º 22
0
 def test_input_event_start(self):
     omxvideo = OmxVideo({'input_events': {'start_event': 'start'}})
     em = EventManager()
     self.assertEqual(len(em.get('start_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('start_event')), 1)  # registered
     self.assertEqual(omxvideo.startEvent._fireCount, 0)
     omxvideo.event_manager.fire('start_event')  # fire without params
     self.assertEqual(omxvideo.startEvent._fireCount, 1)  # performed
     omxvideo.event_manager.get('start_event').fire(
         3)  # fire with number param
     self.assertEqual(omxvideo.startEvent._fireCount, 2)  # performed again
     omxvideo.destroy()
     self.assertEqual(len(em.get('start_event')), 0)  # unregistered
Exemplo n.º 23
0
 def test_delay_runs_multiple_times(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'AA',
             'delay': 10,
             'target': 'BB'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     delay_events.update(10)  # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1)  # B got fired
     delay_events.update(
         10)  # let's move another 10 seconds into the future
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount,
                      1)  # B didn't get fired again
     event_manager.get('AA').fire()
     self.assertEqual(event_manager.get('AA')._fireCount, 2)
     self.assertEqual(event_manager.get('BB')._fireCount,
                      1)  # B didn't get fired again
     delay_events.update(10)  # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('AA')._fireCount, 2)
     self.assertEqual(event_manager.get('BB')._fireCount,
                      2)  # B didn't get fired again
Exemplo n.º 24
0
 def test_halt(self):
     delay_events = DelayEvents({'example': {'source': 'loop', 'delay': 10, 'target': 'loop', 'halt': 'halter'}})
     event_manager = EventManager()
     halterE = event_manager.get('halter')
     self.assertEqual(halterE.getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].haltEvent, halterE)
     self.assertEqual(halterE.getSubscriberCount(), 1)
     self.assertEqual(delay_events._delay_items[0].active, True)
     # start
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # halt
     halterE()
     self.assertEqual(delay_events._delay_items[0].active, False)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
Exemplo n.º 25
0
 def test_halt(self):
     delay_events = DelayEvents({
         'example': {
             'source': 'loop',
             'delay': 10,
             'target': 'loop',
             'halt': 'halter'
         }
     })
     event_manager = EventManager()
     halterE = event_manager.get('halter')
     self.assertEqual(halterE.getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].haltEvent, halterE)
     self.assertEqual(halterE.getSubscriberCount(), 1)
     self.assertEqual(delay_events._delay_items[0].active, True)
     # start
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # halt
     halterE()
     self.assertEqual(delay_events._delay_items[0].active, False)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
Exemplo n.º 26
0
 def test_update_progress_without_specified_dt(self):
     delay_events = DelayEvents({'example': {'source': 'AA', 'delay': 30, 'target': 'BB'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     self.assertEqual(delay_events._delay_items[0].timer, 30)
     delay_events.update()
     self.assertLess(delay_events._delay_items[0].timer, 30)
     self.assertGreater(delay_events._delay_items[0].timer, 29.75)
     sleep(0.25)
     delay_events.update()
     self.assertLess(delay_events._delay_items[0].timer, 29.75)
     self.assertGreater(delay_events._delay_items[0].timer, 29.5)
Exemplo n.º 27
0
 def test_update_without_trigger(self):
     delay_events = DelayEvents({'example': {'source': 'AA', 'delay': 60, 'target': 'BB'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     delay_events.update(62) # 'pretend' 62 seconds have passed
     self.assertEqual(event_manager.get('AA')._fireCount, 0)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
Exemplo n.º 28
0
 def test_pause(self):
     delay_events = DelayEvents({'example': {'source': 'loop', 'delay': 10, 'target': 'loop', 'pause': 'pauser'}})
     event_manager = EventManager()
     pauserE = event_manager.get('pauser')
     self.assertEqual(pauserE.getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].pauseEvent, pauserE)
     self.assertEqual(pauserE.getSubscriberCount(), 1)
     self.assertEqual(delay_events._delay_items[0].active, True)
     # start
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     delay_events.update(6)
     # pause
     pauserE()
     self.assertEqual(delay_events._delay_items[0].active, False)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # resume
     pauserE()
     self.assertEqual(delay_events._delay_items[0].active, True)
     # progress, resumed
     delay_events.update(4)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
Exemplo n.º 29
0
 def test_pause(self):
     delay_events = DelayEvents({
         'example': {
             'source': 'loop',
             'delay': 10,
             'target': 'loop',
             'pause': 'pauser'
         }
     })
     event_manager = EventManager()
     pauserE = event_manager.get('pauser')
     self.assertEqual(pauserE.getSubscriberCount(), 0)
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].pauseEvent, pauserE)
     self.assertEqual(pauserE.getSubscriberCount(), 1)
     self.assertEqual(delay_events._delay_items[0].active, True)
     # start
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     # progress
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     delay_events.update(6)
     # pause
     pauserE()
     self.assertEqual(delay_events._delay_items[0].active, False)
     # progress, halted
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # resume
     pauserE()
     self.assertEqual(delay_events._delay_items[0].active, True)
     # progress, resumed
     delay_events.update(4)
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
Exemplo n.º 30
0
 def test_input_event_load(self):
     omxvideo = OmxVideo({
         'input_events': {
             'load_event': 'load'
         },
         'playlist': ['1', '2', '3', '4']
     })
     em = EventManager()
     self.assertEqual(len(em.get('load_event')), 0)
     omxvideo.setup(em)
     self.assertEqual(len(em.get('load_event')), 1)  # registered
     self.assertEqual(omxvideo.loadEvent._fireCount, 0)
     omxvideo.event_manager.fire('load_event')  # fire without params
     self.assertEqual(omxvideo.loadEvent._fireCount, 1)  # performed
     omxvideo.event_manager.get('load_event').fire(
         3)  # fire with number param
     self.assertEqual(omxvideo.loadEvent._fireCount, 2)  # performed again
     omxvideo.destroy()
     self.assertEqual(len(em.get('load_event')), 0)  # unregistered
Exemplo n.º 31
0
 def test_start_after_halt(self):
     delay_events = DelayEvents({'example': {'source': 'loop', 'delay': 10, 'target': 'loop', 'halt': 'halter'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     # start
     event_manager.get('loop').fire()
     # reach first loop (2nd loop fire)
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # stop
     event_manager.get('halter').fire()
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     # start again
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     # finish another cycle since starting again
     delay_events.update(10)
     self.assertEqual(event_manager.get('loop')._fireCount, 4)
Exemplo n.º 32
0
 def test_update_progress_without_specified_dt(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'AA',
             'delay': 30,
             'target': 'BB'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     self.assertEqual(delay_events._delay_items[0].timer, 30)
     delay_events.update()
     self.assertLess(delay_events._delay_items[0].timer, 30)
     self.assertGreater(delay_events._delay_items[0].timer, 29.75)
     sleep(0.25)
     delay_events.update()
     self.assertLess(delay_events._delay_items[0].timer, 29.75)
     self.assertGreater(delay_events._delay_items[0].timer, 29.5)
Exemplo n.º 33
0
 def test_update_progress(self):
     delay_events = DelayEvents({'example': {'source': 'AA', 'delay': 30, 'target': 'BB'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('AA').fire()
     self.assertEqual(delay_events._delay_items[0].timer, 30)
     delay_events.update(10) # let 10 seconds 'pass'
     self.assertEqual(delay_events._delay_items[0].timer, 20)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
     delay_events.update(10) # let another 10 seconds 'pass'
     self.assertEqual(delay_events._delay_items[0].timer, 10)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
     delay_events.update(10) # let 10 seconds again, reaching 30 second mark
     self.assertEqual(delay_events._delay_items[0].timer, 0)
     self.assertEqual(event_manager.get('AA')._fireCount, 1)
     self.assertEqual(event_manager.get('BB')._fireCount, 1)
Exemplo n.º 34
0
 def test_fire_existing(self):
     em = EventManager()
     event = em.get('some_event')
     self.assertEqual(event._fireCount, 0)
     em.fire('some_event')
     self.assertEqual(event._fireCount, 1)
     event.fire()
     self.assertEqual(event._fireCount, 2)
     event()
     self.assertEqual(event._fireCount, 3)
     em.fire('some_event')
     self.assertEqual(event._fireCount, 4)
Exemplo n.º 35
0
 def test_fire_existing(self):
     em = EventManager()
     event = em.get('some_event')
     self.assertEqual(event._fireCount, 0)
     em.fire('some_event')
     self.assertEqual(event._fireCount, 1)
     event.fire()
     self.assertEqual(event._fireCount, 2)
     event()
     self.assertEqual(event._fireCount, 3)
     em.fire('some_event')
     self.assertEqual(event._fireCount, 4)
Exemplo n.º 36
0
 def test_update_without_trigger(self):
     delay_events = DelayEvents(
         {'example': {
             'source': 'AA',
             'delay': 60,
             'target': 'BB'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     delay_events.update(62)  # 'pretend' 62 seconds have passed
     self.assertEqual(event_manager.get('AA')._fireCount, 0)
     self.assertEqual(event_manager.get('BB')._fireCount, 0)
Exemplo n.º 37
0
    def test_get_creates_event(self):
        em = EventManager()
        self.assertFalse('newbie' in em._events)
        self.assertEqual(em.eventAddedEvent._fireCount, 0)

        event = em.get('newbie')  # creates new event with this ID
        self.assertTrue('newbie' in em._events)
        self.assertEqual(len(em._events), 1)
        self.assertEqual(em._events['newbie'], event)
        self.assertEqual(em.eventAddedEvent._fireCount, 1)
        self.assertTrue('fire' in dir(event))
        self.assertTrue('subscribe' in dir(event))
        self.assertTrue('unsubscribe' in dir(event))
Exemplo n.º 38
0
    def test_get_creates_event(self):
        em = EventManager()
        self.assertFalse('newbie' in em._events)
        self.assertEqual(em.eventAddedEvent._fireCount, 0)

        event = em.get('newbie') # creates new event with this ID
        self.assertTrue('newbie' in em._events)
        self.assertEqual(len(em._events), 1)
        self.assertEqual(em._events['newbie'], event)
        self.assertEqual(em.eventAddedEvent._fireCount, 1)
        self.assertTrue('fire' in dir(event))
        self.assertTrue('subscribe' in dir(event))
        self.assertTrue('unsubscribe' in dir(event))
Exemplo n.º 39
0
 def test_looping_event(self):
     delay_events = DelayEvents({'looper': {'source': 'loop', 'delay': 10, 'target': 'loop'}})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     delay_events.update(10) # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('loop')._fireCount, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     delay_events.update(5) # halfway towards the second trigger
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     delay_events.update(5) # time for the second trigger
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     delay_events.update(10) # 3rd
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     delay_events.update(10) # 4th
     self.assertEqual(event_manager.get('loop')._fireCount, 4)
Exemplo n.º 40
0
 def test_looping_event(self):
     delay_events = DelayEvents(
         {'looper': {
             'source': 'loop',
             'delay': 10,
             'target': 'loop'
         }})
     event_manager = EventManager()
     delay_events.setup(event_manager)
     delay_events.update(10)  # let 10 seconds 'pass'
     self.assertEqual(event_manager.get('loop')._fireCount, 0)
     # trigger source event, in order to trigger the delayed call to the target event
     event_manager.get('loop').fire()
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     delay_events.update(5)  # halfway towards the second trigger
     self.assertEqual(event_manager.get('loop')._fireCount, 1)
     delay_events.update(5)  # time for the second trigger
     self.assertEqual(event_manager.get('loop')._fireCount, 2)
     delay_events.update(10)  # 3rd
     self.assertEqual(event_manager.get('loop')._fireCount, 3)
     delay_events.update(10)  # 4th
     self.assertEqual(event_manager.get('loop')._fireCount, 4)
Exemplo n.º 41
0
 def test_events_triggers_other_events(self):
     e2e = EventToEvent({'event1': ['aa', 'bb', 'cc'], 'event2': ['bb', 'dd'], 'event3': 'bb'})
     event_manager = EventManager()
     e2e.setup(event_manager)
     self.assertEqual(event_manager.get('event1')._fireCount, 0)
     self.assertEqual(event_manager.get('event2')._fireCount, 0)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 0)
     self.assertEqual(event_manager.get('bb')._fireCount, 0)
     self.assertEqual(event_manager.get('cc')._fireCount, 0)
     self.assertEqual(event_manager.get('dd')._fireCount, 0)
     self.assertEqual(event_manager.get('event1').getSubscriberCount(), 3)
     event_manager.get('event1').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 0)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 1)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 0)
     event_manager.get('event2').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 1)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 2)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 1)
     event_manager.get('event3').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 1)
     self.assertEqual(event_manager.get('event3')._fireCount, 1)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 3)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 1)
Exemplo n.º 42
0
 def test_get_maps_non_string_params_to_strings(self):
     em = EventManager()
     self.assertEqual(em.get(3), em.get('3'))
     self.assertEqual(em.get(True), em.get('True'))
Exemplo n.º 43
0
 def test_get_returns_existing_event(self):
     em = EventManager()
     event1 = em.get('bar')
     event2 = em.get('bar')
     self.assertEqual(event1, event2)
     self.assertEqual(len(em._events), 1)
Exemplo n.º 44
0
 def test_fire_new(self):
     em = EventManager()
     em.fire('another')
     event = em.get('another')
     self.assertEqual(event._fireCount, 1)
Exemplo n.º 45
0
 def test_fire_doesnt_create_event(self):
     em = EventManager()
     em.fire('another', create=False)
     event = em.get('another')
     self.assertEqual(event._fireCount, 0)
Exemplo n.º 46
0
 def test_config_to_events_with_iterable_input_returns_input(self):
     em = EventManager()
     self.assertEqual(em.config_to_events(['abc', 'def']), [em.get('abc'), em.get('def')])
Exemplo n.º 47
0
 def test_config_to_events_with_non_iterable_input_returns_list_with_input_as_single_value(self):
     em = EventManager()
     self.assertEqual(em.config_to_events('abc'), [em.get('abc')])
Exemplo n.º 48
0
 def test_get_returns_existing_event(self):
     em = EventManager()
     event1 = em.get('bar')
     event2 = em.get('bar')
     self.assertEqual(event1, event2)
     self.assertEqual(len(em._events), 1)
Exemplo n.º 49
0
 def test_fire_new(self):
     em = EventManager()
     em.fire('another')
     event = em.get('another')
     self.assertEqual(event._fireCount, 1)
Exemplo n.º 50
0
 def test_config_to_events_with_iterable_input_returns_input(self):
     em = EventManager()
     self.assertEqual(em.config_to_events(['abc', 'def']),
                      [em.get('abc'), em.get('def')])
Exemplo n.º 51
0
 def test_fire_doesnt_create_event(self):
     em = EventManager()
     em.fire('another', create=False)
     event = em.get('another')
     self.assertEqual(event._fireCount, 0)
Exemplo n.º 52
0
 def test_events_triggers_other_events(self):
     e2e = EventToEvent({
         'event1': ['aa', 'bb', 'cc'],
         'event2': ['bb', 'dd'],
         'event3': 'bb'
     })
     event_manager = EventManager()
     e2e.setup(event_manager)
     self.assertEqual(event_manager.get('event1')._fireCount, 0)
     self.assertEqual(event_manager.get('event2')._fireCount, 0)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 0)
     self.assertEqual(event_manager.get('bb')._fireCount, 0)
     self.assertEqual(event_manager.get('cc')._fireCount, 0)
     self.assertEqual(event_manager.get('dd')._fireCount, 0)
     self.assertEqual(event_manager.get('event1').getSubscriberCount(), 3)
     event_manager.get('event1').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 0)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 1)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 0)
     event_manager.get('event2').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 1)
     self.assertEqual(event_manager.get('event3')._fireCount, 0)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 2)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 1)
     event_manager.get('event3').fire()
     self.assertEqual(event_manager.get('event1')._fireCount, 1)
     self.assertEqual(event_manager.get('event2')._fireCount, 1)
     self.assertEqual(event_manager.get('event3')._fireCount, 1)
     self.assertEqual(event_manager.get('aa')._fireCount, 1)
     self.assertEqual(event_manager.get('bb')._fireCount, 3)
     self.assertEqual(event_manager.get('cc')._fireCount, 1)
     self.assertEqual(event_manager.get('dd')._fireCount, 1)
Exemplo n.º 53
0
 def test_config_to_events_with_non_iterable_input_returns_list_with_input_as_single_value(
         self):
     em = EventManager()
     self.assertEqual(em.config_to_events('abc'), [em.get('abc')])
Exemplo n.º 54
0
 def test_get_maps_non_string_params_to_strings(self):
     em = EventManager()
     self.assertEqual(em.get(3), em.get('3'))
     self.assertEqual(em.get(True), em.get('True'))