def test_dispatcher(self): dispatcher = EventDispatcher() for event_id in ( STRING_EVENT_ID, OBJECT_EVENT_ID, NUMERIC_EVENT_ID, ): listener = mock.MagicMock() assert not dispatcher.has_listeners(event_id) dispatcher.add_listener(event_id, listener) assert dispatcher.has_listeners(event_id) assert listener.call_count == 0 e = dispatcher.dispatch(event_id) assert listener.call_count == 1 assert not e.propagation_stopped e = dispatcher.dispatch(event_id) assert listener.call_count == 2 assert not e.propagation_stopped
def test_one_pass(): plugin = ConsoleOutputPlugin() dispatcher = EventDispatcher() plugin.register(dispatcher) graph = bonobo.Graph() context = MagicMock(spec=GraphExecutionContext(graph)) dispatcher.dispatch(events.START, events.ExecutionEvent(context)) dispatcher.dispatch(events.TICK, events.ExecutionEvent(context)) dispatcher.dispatch(events.STOPPED, events.ExecutionEvent(context)) plugin.unregister(dispatcher)