コード例 #1
0
def test_publish_no_transceiver():
    """
    Verify publisher can publish even with no means of transceiver. May want to
    consider raising an error if publish is called with no tranceiver...
    """
    p = Publisher(5)
    p.publish(b"hello world")
コード例 #2
0
def test_many_pub_one_sub(Transceiver):
    """
    Get many publisher instances and many subscribers and verify that the 
    messages are published to the subscriber
    """
    TOPIC = 10
    DIFF_TOPIC = 11
    pubs = [Publisher(TOPIC) for _ in range(10)]
    diff_pubs = [Publisher(DIFF_TOPIC) for _ in range(10)]

    cb = get_callback()
    sub = Subscriber(TOPIC, cb)

    Transceiver.connect([sub] + pubs + diff_pubs)

    expected_log = []
    pubs[0].publish(b"hello")
    expected_log.append(b"hello")
    assert cb.log == expected_log

    for p in diff_pubs:
        p.publish(b"kaput")
    assert cb.log == [b"hello"]

    for p in pubs:
        p.publish(b"works")
        expected_log.append(b"works")
    assert cb.log == expected_log
コード例 #3
0
def test_use_transceiver(Transceiver):
    """
    Verify publisher can use a transceiver object
    """
    # set up publisher
    p = Publisher(10)
    t = Transceiver()
    p.use(t)
コード例 #4
0
def test_use_multiple_transceivers(Transceiver):
    """
    Verify publisher can use multiple transceivers
    """
    # set up publisher
    p = Publisher(5)
    ts = [Transceiver() for _ in range(10)]
    for t in ts:
        p.use(t)
コード例 #5
0
def test_one_pub_many_sub(Transceiver):
    """
    Get one publisher instance and many subscribers and verify that the 
    messages are published to all subscribers
    """
    TOPIC = 10
    DIFF_TOPIC = 11
    p = Publisher(TOPIC)

    sub_callbacks = [get_callback() for _ in range(10)]
    subs = [Subscriber(TOPIC, cb) for cb in sub_callbacks]

    diff_sub_callbacks = [get_callback() for _ in range(10)]
    diff_subs = [Subscriber(DIFF_TOPIC, cb) for cb in diff_sub_callbacks]
    Transceiver.connect([p] + subs + diff_subs)

    p.publish(b"hello")
    for cb in sub_callbacks:
        assert cb.log == [b"hello"]
    for cb in diff_sub_callbacks:
        assert cb.log == []

    p.publish(b"goodbye")
    for cb in sub_callbacks:
        assert cb.log == [b"hello", b"goodbye"]
    for cb in diff_sub_callbacks:
        assert cb.log == []
コード例 #6
0
def test_publish_one_transceiver(Transceiver):
    """
    Verify publish works with when using one tranceiver
    """
    p = Publisher(5)
    t = Transceiver()
    p.use(t)
    p.publish(b"hello world")
コード例 #7
0
def test_many_pub_many_sub(Transceiver):
    """
    Get many publisher instances and many subscribers and verify that the 
    messages are published to all subscribers
    """
    TOPIC = 10
    DIFF_TOPIC = 11
    pubs = [Publisher(TOPIC) for _ in range(10)]
    diff_pubs = [Publisher(DIFF_TOPIC) for _ in range(10)]

    sub_callbacks = [get_callback() for _ in range(10)]
    subs = [Subscriber(TOPIC, cb) for cb in sub_callbacks]

    diff_sub_callbacks = [get_callback() for _ in range(10)]
    diff_subs = [Subscriber(DIFF_TOPIC, cb) for cb in diff_sub_callbacks]
    Transceiver.connect(pubs + diff_pubs + subs + diff_subs)

    expected_log = []
    expected_diff_log = []

    pubs[0].publish(b"sign")
    expected_log.append(b"sign")
    for cb in sub_callbacks:
        assert cb.log == expected_log
    for cb in diff_sub_callbacks:
        assert cb.log == expected_diff_log

    for p in pubs:
        p.publish(b"open eyes")
        expected_log.append(b"open eyes")
    for p in diff_pubs:
        p.publish(b"belong")
        expected_diff_log.append(b"belong")
    for cb in sub_callbacks:
        assert cb.log == expected_log
    for cb in diff_sub_callbacks:
        assert cb.log == expected_diff_log
コード例 #8
0
def test_publish_many_transceivers(Transceiver):
    """
    Verify publish works with when using multiple tranceivers
    """
    p = Publisher(5)
    ts = [Transceiver() for _ in range(10)]
    for t in ts:
        p.use(t)
    p.publish(b"goodbye yellow brick road")
コード例 #9
0
def test_one_pub_one_sub_one_connection(Transceiver):
    """
    Get one publisher instance and one subscriber instance and connect them
    over the same topic and confirm that messages get sent 
    """
    TOPIC = 10
    p = Publisher(TOPIC)
    cb = get_callback()
    s = Subscriber(TOPIC, cb)
    Transceiver.connect([p, s])
    p.publish(b"hello")
    assert cb.log == [b"hello"]
    p.publish(b"goodbye")
    assert cb.log == [b"hello", b"goodbye"]
コード例 #10
0
def test_one_pub_one_sub_many_connections(Transceiver):
    """
    Get one publisher instance and one subscriber instance and connect them
    with multiple transceivers and verify that the message only gets delivered
    once... is that a property we want to enforce to some capacity?
    """
    TOPIC = 10
    p = Publisher(TOPIC)
    cb = get_callback()
    s = Subscriber(TOPIC, cb)
    for i in range(10):
        Transceiver.connect([p, s])
    p.publish(b"hello")
    assert cb.log == [b"hello"]
    p.publish(b"goodbye")
    assert cb.log == [b"hello", b"goodbye"]
コード例 #11
0
def test_initialization():
    """
    Verify publisher can take in a topic and not crash
    """
    p = Publisher(10)