Exemplo n.º 1
0
def test_can_subscribe_to_unpublished_message():
    bus = Bus()
    func = lambda x: x
    bus.subscribe("some message", func)

    assert "some message" in bus.subscribers
    assert len(bus.subscribers["some message"]) == 1
    assert bus.subscribers["some message"][0] is func
Exemplo n.º 2
0
def test_can_subscribe_and_get_results_on_publish():
    results = []
    def proc(x):
        results.append(x)

    bus = Bus()
    func = proc
    bus.subscribe("some message", func)

    bus.publish("some message", x="text")

    assert len(results) == 1
    assert results[0] == "text"
Exemplo n.º 3
0
def test_can_subscribe_and_get_results_on_publish_for_more_than_one_subscriber():
    results = []
    def proc(x):
        results.append(x + "1")
    def proc2(x):
        results.append(x + "2")

    bus = Bus()
    bus.subscribe("some message", proc)
    bus.subscribe("some message", proc2)

    bus.publish("some message", x="text")

    assert len(results) == 2
    assert results[0] == "text1"
    assert results[1] == "text2"
Exemplo n.º 4
0
def test_bus_can_publish_messages_with_no_listeners():
    bus = Bus()
    bus.publish("some message", text="some")

    assert True, "If it got this far the message was published without errors."