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)
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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
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
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
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
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)
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
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)
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
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))
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
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
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))
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)
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)
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
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)
def test_setup_with_event_manager(self): em = EventManager() oscoutput = OscOutput({'ip': '127.0.0.1'}) oscoutput.setup(em) self.assertEqual(oscoutput.event_manager, em) self.assertIsNotNone(oscoutput.client) self.assertTrue(oscoutput.connected)
def test_destroy(self): sr = SshRemote({'hostname': 'localhost', 'username': '******', 'password': '******'}) sr.setup(EventManager()) sr.destroy() self.assertIsNone(sr.ip) self.assertFalse(sr.connected) self.assertIsNone(sr.client) self.assertIsNone(sr.event_manager)
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)
def test_destroy(self): webserver = WebServer() em = EventManager() webserver.setup(em) self.assertTrue(webserver.isAlive()) self.assertEqual(webserver.event_manager, em) webserver.destroy() self.assertFalse(webserver.isAlive()) self.assertIsNone(webserver.event_manager)
def test_midi_note_triggers_multiple_events(self): midiinput = MidiInput({'output_events': {144: {36: ['begin', 'middle', 'end']}}}) midiinput.setup(EventManager(), midi_port=MidiPortMock([[[144,36]]])) self.assertEqual(midiinput.event_manager.get('begin')._fireCount, 0) self.assertEqual(midiinput.event_manager.get('middle')._fireCount, 0) self.assertEqual(midiinput.event_manager.get('end')._fireCount, 0) midiinput.update() # process mocked midi message self.assertEqual(midiinput.event_manager.get('begin')._fireCount, 1) self.assertEqual(midiinput.event_manager.get('middle')._fireCount, 1) self.assertEqual(midiinput.event_manager.get('end')._fireCount, 1)
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
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)
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)
def test_output_events_explicit_value_with_auto_enabled(self): oscinput = OscInput( {'output_events': { 'auto': True, '/explicit': 'some_event' }}) oscinput.setup(EventManager()) self.assertEqual( oscinput.event_manager.get('some_event')._fireCount, 0) oscinput._onDefault('/explicit') self.assertEqual( oscinput.event_manager.get('some_event')._fireCount, 1)
def test_input_event_with_params(self): oscoutput = OscOutput( {'input_events': { 'params_event': '/some/message' }}) oscoutput.setup(EventManager()) # capture all outgoing messages self._messages = [] oscoutput.messageEvent += self._onMessage2 oscoutput.event_manager.get('params_event').fire('param1', 2, 3.0) self.assertEqual(self._messages[-1].values(), ['param1', 2, 3.0])
def setUpClass(cls): cls.event_manager = EventManager() cls.webserver = WebServer({ 'port': 2033, 'serve': 'tests/data', 'output_events': { '/api/start': 'startEvent' }, 'responses': { '/system/stop': 'Shutting down...' } }) cls.webserver.setup(cls.event_manager)
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)
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)
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)
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)
def test_input_event_triggers_osc_message(self): oscoutput = OscOutput( {'input_events': { 'some_event': '/some/message' }}) oscoutput.setup(EventManager()) self.message_addresses = [] oscoutput.messageEvent += self._onMessage self.assertEqual(oscoutput.messageEvent._fireCount, 0) oscoutput.event_manager.fire('some_event') self.assertEqual(oscoutput.messageEvent._fireCount, 1) self.assertEqual(self.message_addresses, ['/some/message']) oscoutput.event_manager.fire('some_event_tother') self.assertEqual(oscoutput.messageEvent._fireCount, 1) self.assertEqual(self.message_addresses, ['/some/message']) oscoutput.event_manager.fire('some_event') self.assertEqual(self.message_addresses, ['/some/message', '/some/message'])
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)
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)
def test_fire_doesnt_create_event(self): em = EventManager() em.fire('another', create=False) event = em.get('another') self.assertEqual(event._fireCount, 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')])
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)
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'))
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)
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')])
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')])
def test_fire_new(self): em = EventManager() em.fire('another') event = em.get('another') self.assertEqual(event._fireCount, 1)
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)
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')])
def test_fire_doesnt_create_event(self): em = EventManager() em.fire('another', create=False) event = em.get('another') self.assertEqual(event._fireCount, 0)