예제 #1
0
def test_event_hook():
    mock_hook = MagicMock()

    event_emitter = EventEmitter()
    event_emitter.register_hook(mock_hook)

    for event_type in EventType:
        event_emitter.fire(event_type, None)
        assert getattr(mock_hook, event_type.name).called is True
예제 #2
0
def test_event_hook(event_name):
    event_value = getattr(EventType, event_name)
    mock_hook = MagicMock(spec=EventHook)

    event_emitter = EventEmitter()
    event_emitter.register_hook(mock_hook)

    event_emitter.fire(event_value, None)
    assert getattr(mock_hook, event_name).called is True
예제 #3
0
def test_event_hook(event_name):
    event_value = getattr(EventType, event_name)
    mock_hook = MagicMock(spec=EventHook)

    event_emitter = EventEmitter()
    event_emitter.register_hook(mock_hook)

    yield event_emitter.fire(event_value, None)
    assert getattr(mock_hook, event_name).called is True
예제 #4
0
def test_decorator_registration():
    event_emitter = EventEmitter()
    registrar = EventRegistrar(event_emitter)

    called = [False]

    @registrar.before_send_request
    def foo():
        called[0] = True

    event_emitter.fire(EventType.before_send_request)
    assert called[0] is True
예제 #5
0
def test_decorator_registration():
    event_emitter = EventEmitter()
    registrar = EventRegistrar(event_emitter)

    called = [False, False]

    # Multiple handlers can be defined for the same event.
    @registrar.before_send_request
    def foo():
        called[0] = True

    @registrar.before_send_request
    def bar():
        called[1] = True

    event_emitter.fire(EventType.before_send_request)

    assert called[0] is True
    assert called[1] is True