Ejemplo n.º 1
0
def test_off__11():
    """
    Returns True if trying to detach a non-existent listener.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event", bool) is True
Ejemplo n.º 2
0
def test_off__10():
    """
    Returns True if the specified event has been deleted.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event") is True
Ejemplo n.º 3
0
def test_off__12():
    """
    Returns True if the specified listener has been detached.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event", callable) is True
Ejemplo n.º 4
0
def test_events__4():
    """
    True event can be retrieved.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert True in emitter.events()
Ejemplo n.º 5
0
def test_off__12():
    """
    Returns True if the specified listener has been detached.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event", callable) is True
Ejemplo n.º 6
0
def test_events__4():
    """
    True event can be retrieved.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert True in emitter.events()
Ejemplo n.º 7
0
def test_events__3():
    """
    False event can be retrieved.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert False in emitter.events()
Ejemplo n.º 8
0
def test_listeners__6():
    """
    Should not return the original object, but a copy.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.listeners("event") is not emitter.listeners("event")
Ejemplo n.º 9
0
def test_events__5():
    """
    Should not return the original object, but a copy.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.events() is not emitter.events()
Ejemplo n.º 10
0
def test_listeners__4():
    """
    Get the listeners for the False event.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert callable in emitter.listeners(False)
Ejemplo n.º 11
0
def test_listeners__5():
    """
    Get the listeners for the True event.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert callable in emitter.listeners(True)
Ejemplo n.º 12
0
def test_off__10():
    """
    Returns True if the specified event has been deleted.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event") is True
Ejemplo n.º 13
0
def test_listeners__6():
    """
    Should not return the original object, but a copy.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.listeners("event") is not emitter.listeners("event")
Ejemplo n.º 14
0
def test_events__3():
    """
    False event can be retrieved.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert False in emitter.events()
Ejemplo n.º 15
0
def test_off__11():
    """
    Returns True if trying to detach a non-existent listener.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.off("event", bool) is True
Ejemplo n.º 16
0
def test_listeners__4():
    """
    Get the listeners for the False event.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert callable in emitter.listeners(False)
Ejemplo n.º 17
0
def test_listeners__5():
    """
    Get the listeners for the True event.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert callable in emitter.listeners(True)
Ejemplo n.º 18
0
def test_events__5():
    """
    Should not return the original object, but a copy.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert emitter.events() is not emitter.events()
Ejemplo n.º 19
0
def test_on__3():
    """
    False is a valid event.
    """
    emitter = Emitter()
    emitter.on(False, callable)

    assert False in emitter.events()
Ejemplo n.º 20
0
def test_on__5():
    """
    A listener must be callable.
    """
    emitter = Emitter()

    with pytest.raises(TypeError):
        emitter.on("event", "")
Ejemplo n.º 21
0
def test_on__4():
    """
    A string is a valid event.
    """
    emitter = Emitter()
    emitter.on("event", callable)

    assert "event" in emitter.events()
Ejemplo n.º 22
0
def test_emit__5():
    """
    Returns True when emitting an event.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    result = emitter.emit("event")
    assert result is True
Ejemplo n.º 23
0
def test_off__8():
    """
    Returns True if all events are deleted.
    """
    emitter = Emitter()
    emitter.on("event1", callable)
    emitter.on("event2", callable)
    assert emitter.off() is True
Ejemplo n.º 24
0
def test_on__2():
    """
    True is a valid event.
    """
    emitter = Emitter()
    emitter.on(True, callable)

    assert True in emitter.events()
Ejemplo n.º 25
0
def test_on__1():
    """
    User cannot register a None event.
    """
    emitter = Emitter()

    with pytest.raises(ValueError):
        emitter.on(None, callable)
Ejemplo n.º 26
0
def test_on__4():
    """
    A string is a valid event.
    """
    emitter = Emitter()
    emitter.on("event", callable)

    assert "event" in emitter.events()
Ejemplo n.º 27
0
def test_on__1():
    """
    User cannot register a None event.
    """
    emitter = Emitter()

    with pytest.raises(ValueError):
        emitter.on(None, callable)
Ejemplo n.º 28
0
def test_on__5():
    """
    A listener must be callable.
    """
    emitter = Emitter()

    with pytest.raises(TypeError):
        emitter.on("event", "")
Ejemplo n.º 29
0
def test_on__2():
    """
    True is a valid event.
    """
    emitter = Emitter()
    emitter.on(True, callable)

    assert True in emitter.events()
Ejemplo n.º 30
0
def test_off__8():
    """
    Returns True if all events are deleted.
    """
    emitter = Emitter()
    emitter.on("event1", callable)
    emitter.on("event2", callable)
    assert emitter.off() is True
Ejemplo n.º 31
0
def test_emit__5():
    """
    Returns True when emitting an event.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    result = emitter.emit("event")
    assert result is True
Ejemplo n.º 32
0
def test_on__3():
    """
    False is a valid event.
    """
    emitter = Emitter()
    emitter.on(False, callable)

    assert False in emitter.events()
Ejemplo n.º 33
0
def test_off__1():
    """
    Called with no arguments, it removes all the events.
    """
    emitter = Emitter()
    emitter.on("raccoon", callable)
    emitter.on("fox", callable)
    emitter.off()
    assert emitter.events() == set()
Ejemplo n.º 34
0
def test_emit__7():
    """
    False event can be emitted.
    """
    emitter = Emitter()
    l = []
    emitter.on(False, lambda: l.append(1))
    emitter.emit(False)
    assert 1 in l
Ejemplo n.º 35
0
def test_off__1():
    """
    Called with no arguments, it removes all the events.
    """
    emitter = Emitter()
    emitter.on("raccoon", callable)
    emitter.on("fox", callable)
    emitter.off()
    assert emitter.events() == set()
Ejemplo n.º 36
0
def test_emit__8():
    """
    True event can be emitted.
    """
    emitter = Emitter()
    l = []
    emitter.on(True, lambda: l.append(1))
    emitter.emit(True)
    assert 1 in l
Ejemplo n.º 37
0
def test_emit__7():
    """
    False event can be emitted.
    """
    emitter = Emitter()
    l = []
    emitter.on(False, lambda: l.append(1))
    emitter.emit(False)
    assert 1 in l
Ejemplo n.º 38
0
def test_emit__8():
    """
    True event can be emitted.
    """
    emitter = Emitter()
    l = []
    emitter.on(True, lambda: l.append(1))
    emitter.emit(True)
    assert 1 in l
Ejemplo n.º 39
0
def test_events__2():
    """
    Returns a set containing all the registered events.
    """
    emitter = Emitter()
    emitter.on("event1", callable)
    emitter.on("event2", callable)
    emitter.on("event3", callable)
    events = emitter.events()
    assert events == {"event1", "event2", "event3"}
Ejemplo n.º 40
0
def test_off__6():
    """
    A listener of the False event can be removed.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert callable in emitter.listeners(False)

    emitter.off(False, callable)
    assert callable not in emitter.listeners(False)
Ejemplo n.º 41
0
def test_off__4():
    """
    False event can be removed.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert False in emitter.events()

    emitter.off(False)
    assert False not in emitter.events()
Ejemplo n.º 42
0
def test_off__5():
    """
    True event can be removed.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert True in emitter.events()

    emitter.off(True)
    assert True not in emitter.events()
Ejemplo n.º 43
0
def test_events__2():
    """
    Returns a set containing all the registered events.
    """
    emitter = Emitter()
    emitter.on("event1", callable)
    emitter.on("event2", callable)
    emitter.on("event3", callable)
    events = emitter.events()
    assert events == {"event1", "event2", "event3"}
Ejemplo n.º 44
0
def test_emit__3():
    """
    Only the listeners of the specified event should be triggered.
    """
    emitter = Emitter()
    l = []
    emitter.on("event1", lambda: l.append(1))
    emitter.on("event2", lambda: l.append(2))
    emitter.emit("event1")
    assert l == [1]
Ejemplo n.º 45
0
def test_off__7():
    """
    A listener of the True event can be removed.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert callable in emitter.listeners(True)

    emitter.off(True, callable)
    assert callable not in emitter.listeners(True)
Ejemplo n.º 46
0
def test_off__13():
    """
    Delete the event if no more listeners.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert "event" in emitter.events()

    emitter.off("event", callable)
    assert emitter.events() == set()
Ejemplo n.º 47
0
def test_off__13():
    """
    Delete the event if no more listeners.
    """
    emitter = Emitter()
    emitter.on("event", callable)
    assert "event" in emitter.events()

    emitter.off("event", callable)
    assert emitter.events() == set()
Ejemplo n.º 48
0
def test_off__6():
    """
    A listener of the False event can be removed.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert callable in emitter.listeners(False)

    emitter.off(False, callable)
    assert callable not in emitter.listeners(False)
Ejemplo n.º 49
0
def test_emit__3():
    """
    Only the listeners of the specified event should be triggered.
    """
    emitter = Emitter()
    l = []
    emitter.on("event1", lambda: l.append(1))
    emitter.on("event2", lambda: l.append(2))
    emitter.emit("event1")
    assert l == [1]
Ejemplo n.º 50
0
def test_off__7():
    """
    A listener of the True event can be removed.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert callable in emitter.listeners(True)

    emitter.off(True, callable)
    assert callable not in emitter.listeners(True)
Ejemplo n.º 51
0
def test_off__5():
    """
    True event can be removed.
    """
    emitter = Emitter()
    emitter.on(True, callable)
    assert True in emitter.events()

    emitter.off(True)
    assert True not in emitter.events()
Ejemplo n.º 52
0
def test_off__4():
    """
    False event can be removed.
    """
    emitter = Emitter()
    emitter.on(False, callable)
    assert False in emitter.events()

    emitter.off(False)
    assert False not in emitter.events()
Ejemplo n.º 53
0
def test_on__7():
    """
    Multiple listeners can be registered for an event.
    """
    emitter = Emitter()

    emitter.on("event", callable)
    emitter.on("event", bool)

    assert callable in emitter.listeners("event")
    assert bool in emitter.listeners("event")
Ejemplo n.º 54
0
def test_on__6():
    """
    Multiple events can be registered.
    """
    emitter = Emitter()

    emitter.on("event1", callable)
    emitter.on("event2", callable)

    assert "event1" in emitter.events()
    assert "event2" in emitter.events()
Ejemplo n.º 55
0
def test_emit__1():
    """
    All the listeners of an event must be triggered.
    """
    emitter = Emitter()
    l = []
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(1))
    emitter.emit("event")
    assert len(l) == 3
Ejemplo n.º 56
0
def test_emit__2():
    """
    Listeners are triggered in order of insertion.
    """
    emitter = Emitter()
    l = []
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(2))
    emitter.on("event", lambda: l.append(3))
    emitter.emit("event")
    assert l == [1, 2, 3]
Ejemplo n.º 57
0
def test_on__7():
    """
    Multiple listeners can be registered for an event.
    """
    emitter = Emitter()

    emitter.on("event", callable)
    emitter.on("event", bool)

    assert callable in emitter.listeners("event")
    assert bool in emitter.listeners("event")
Ejemplo n.º 58
0
def test_emit__1():
    """
    All the listeners of an event must be triggered.
    """
    emitter = Emitter()
    l = []
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(1))
    emitter.emit("event")
    assert len(l) == 3
Ejemplo n.º 59
0
def test_emit__2():
    """
    Listeners are triggered in order of insertion.
    """
    emitter = Emitter()
    l = []
    emitter.on("event", lambda: l.append(1))
    emitter.on("event", lambda: l.append(2))
    emitter.on("event", lambda: l.append(3))
    emitter.emit("event")
    assert l == [1, 2, 3]
Ejemplo n.º 60
0
def test_on__6():
    """
    Multiple events can be registered.
    """
    emitter = Emitter()

    emitter.on("event1", callable)
    emitter.on("event2", callable)

    assert "event1" in emitter.events()
    assert "event2" in emitter.events()