Beispiel #1
0
def test_on():
    """api.on() works as advertised"""

    count = {"#": 0}

    def on_event():
        count["#"] += 1

    pipeline.on("some_event", on_event)
    assert_equals(count["#"], 0)
    pipeline.emit("some_event")
    assert_equals(count["#"], 1)
Beispiel #2
0
def test_on_with_garbage_callback():
    """api.on() runs all callbacks, unless they've been garbage collected"""

    count = {"#": 0}

    def on_goodbye():
        count["#"] += 1

    pipeline.on("some_event", on_goodbye)
    assert_equals(count["#"], 0)
    pipeline.emit("some_event")
    assert_equals(count["#"], 1)
    del on_goodbye
    pipeline.emit("some_event")
    assert_equals(count["#"], 1)
Beispiel #3
0
def test_on_with_failing_callback():
    """api.on() runs all callbacks, regardless of some failing"""

    count = {"#": 0}

    def bad_event():
        count["#"] -= 1
        raise Exception("I'm a dick")

    def good_event():
        count["#"] += 1

    pipeline.on("some_event", bad_event)
    pipeline.on("some_event", good_event)
    assert_equals(count["#"], 0)
    pipeline.emit("some_event")
    assert_equals(count["#"], 0)