예제 #1
0
def test_subscribe():
    p = Publisher()
    result = []
    def callback(data):
        result.append(data)
    p.subscribe('test', callback)
    p.publish('test', 4)
    assert result[0] == 4
    p.publish('test', 4)
    assert result[1] == 4
    p.publish('test2', 4)
    assert len(result) == 2
    p.unsubscribe('test', callback)
    p.publish('test', 4)
    assert len(result) == 2
예제 #2
0
파일: test.py 프로젝트: raulb/whitebrd.me
def test_subscribe():
    p = Publisher()
    result = []

    def callback(data):
        result.append(data)

    p.subscribe('test', callback)
    p.publish('test', 4)
    assert result[0] == 4
    p.publish('test', 4)
    assert result[1] == 4
    p.publish('test2', 4)
    assert len(result) == 2
    p.unsubscribe('test', callback)
    p.publish('test', 4)
    assert len(result) == 2
예제 #3
0
from publisher import Publisher
from subscriber import Subscriber, DifferentSubscriber

andre = Subscriber('Andre')
ivan = Subscriber('Ivan')
igor = DifferentSubscriber('Igor')
oki = DifferentSubscriber('Oki')

pub = Publisher()

pub.subscribe(andre)
pub.subscribe(ivan)
pub.subscribe(igor, igor.mycallback)
pub.subscribe(oki, oki.mycallback)

pub.broadcast('Hello all!')

pub.unsubscribe(oki)

pub.broadcast('Bye!')