from duck_preview.dispatcher.frame_dispatcher import FrameDispatcher def test_subscribe_notified(): dispatcher = FrameDispatcher() received = [] def cb(frame): received.append(frame) dispatcher.subscribe(cb) dispatcher.on_frame("test") assert received == ["test"] def test_unsubscribe_not_notified(): dispatcher = FrameDispatcher() received = [] def cb(frame): received.append(frame) dispatcher.subscribe(cb) dispatcher.unsubscribe(cb) dispatcher.on_frame("test") assert received == [] def test_multiple_subscribers(): dispatcher = FrameDispatcher() received_1 = [] received_2 = [] def cb1(frame): received_1.append(frame) def cb2(frame): received_2.append(frame) dispatcher.subscribe(cb1) dispatcher.subscribe(cb2) dispatcher.on_frame("test") assert received_1 == ["test"] assert received_2 == ["test"]