Ejemplo n.º 1
0
def test_dispatcher_topic_doesnt_contain_hook(capsys):
    disp = EventDispatcher()
    evt = Event(name='emit signal', context='test')
    evt.enabled = True
    evt.topics.append({})
    disp.dispatch(evt, 'hook', 1234)
    captured = capsys.readouterr()
    assert captured.out == ""
Ejemplo n.º 2
0
def test_dispatcher_single_topic(capsys):
    disp = EventDispatcher()
    evt = Event(name='emit signal', context='test')
    evt.enabled = True

    def handler(context, data):
        print(context.event.metadata, context.hook, data)

    evt.topics.append({'hook': [handler]})
    disp.dispatch(evt, 'hook', 1234)
    captured = capsys.readouterr()
    assert captured.out == """\
Ejemplo n.º 3
0
def test_dispatcher_alter_event_topic_content_while_dispatch(capsys):
    disp = EventDispatcher()
    evt = Event(name='emit signal', context='test')
    evt.enabled = True

    def handler(context, data):
        print(context.event.metadata, context.hook, data)
        t['hook'].clear()

    evt.topics.append({'hook': [handler]})
    t = {'hook': [handler]}
    evt.topics.append(t)

    disp.dispatch(evt, 'hook', 1234)
    print('#2')
    disp.dispatch(evt, 'hook', 1234)
    captured = capsys.readouterr()
    assert captured.out == """\