def test_event_dispatch_no_dispatcher(capsys): evt = Event(name='cross red light', context='test') evt.enabled = True def handler(context, data): print(context.hook, context.event.metadata, data.value) evt.topics.append({ 'init': [handler], }) evt.dispatch(hook='init', data='handle me') captured = capsys.readouterr() assert captured.out == ""
def test_event_dispatch_enable(capsys): evt = Event(name='cross red light', context='test') evt.dispatcher = EventDispatcher() def handler(context, data): print(context.hook, context.event.metadata, data) evt.topics.append({ 'enable': [handler], 'init': [handler], }) evt.enabled = True evt.enabled = True # check does not dispatch if no change evt.dispatch(hook='init', data='handle me') captured = capsys.readouterr() assert captured.out == """\