def test_publishing_ride_message_with_args(self):
     PUBLISHER.subscribe(self._listener, RideMessage)
     msg_obj = RideTestMessageWithAttrs(foo='bar', bar='foo')
     msg_obj.publish()
     assert_equal(self._msg, msg_obj)
     assert_equal(self._msg.foo, 'bar')
     assert_equal(self._msg.bar, 'foo')
 def test_subscribe_broken_listener_ride_log_broken(self, p_log):
     PUBLISHER.subscribe(self._broken_listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._broken_listener, RideLogException)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     p_log.assert_called_once()
     assert_true(isinstance(self._msg, RideLogException))
     assert_equal(len(TestPublisher.cls_msgs), 2)
 def test_subscribe_multi_listeners_inherit_topic(self):
     PUBLISHER.subscribe(self._listener, RideMessage)
     PUBLISHER.subscribe(_common_listener, RideMessage)
     PUBLISHER.subscribe(self._static_listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._class_listener, RideTestMessageWithAttrs)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     PUBLISHER.publish(RideTestMessageWithAttrs, 'test')
     assert_equal(len(TestPublisher.cls_msgs), 4 * 2)
Пример #4
0
    def publish(self):
        """Publishes the message.

        All listeners that have subscribed to the topic of this message will be
        called with the this instance as an argument.

        Notifications are sent sequentially. Due to the limitations of current
        implementation, if any of the listeners raises an exception, subsequent
        listeners will not get the notification.
        """
        from robotide.publish.publisher import PUBLISHER
        PUBLISHER.publish(self.__class__, self)
 def test_unsubscribe_all_input_none(self):
     PUBLISHER.subscribe(self._listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._static_listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._class_listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(_common_listener, RideTestMessageWithAttrs)
     dummy_obj = DummyClass()
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     assert_equal(len(TestPublisher.cls_msgs), 5)
     PUBLISHER.unsubscribe_all()
     msg_obj.publish()
     assert_equal(len(TestPublisher.cls_msgs), 5)
 def test_unsubscribe_all(self):
     PUBLISHER.subscribe(self._listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._static_listener, RideTestMessageWithAttrs)
     PUBLISHER.subscribe(self._class_listener, RideTestMessageWithAttrs)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     assert_equal(len(TestPublisher.cls_msgs), 3)
     PUBLISHER.unsubscribe_all(self)
     msg_obj.publish()
     assert_equal(len(TestPublisher.cls_msgs), 3)
 def test_subscribe_common_method(self):
     PUBLISHER.subscribe(_common_listener, RideTestMessageWithAttrs)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     assert_equal(TestPublisher.cls_msg, msg_obj)
 def test_subscribe_broken_listener(self, p_log):
     PUBLISHER.subscribe(self._broken_listener, RideTestMessageWithAttrs)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     assert_equal(self._msg, msg_obj)
     p_log.assert_called_once()
 def test_unsubscribe_invalid_topic(self):
     PUBLISHER.subscribe(self._listener, RideTestMessageWithAttrs)
     assert_raises(TypeError, PUBLISHER.unsubscribe, self._listener,
                   'RideTestMessageWithAttrs')
     PUBLISHER.publish(RideTestMessageWithAttrs, 'test')
     assert_equal(self._msg, 'test')
 def test_unsubscribe_ride_message_publish(self):
     PUBLISHER.subscribe(self._listener, RideTestMessageWithAttrs)
     PUBLISHER.unsubscribe(self._listener, RideTestMessageWithAttrs)
     PUBLISHER.publish(RideTestMessageWithAttrs, 'test')
     assert_equal(self._msg, '')
 def test_unsubscribe_ride_message(self):
     PUBLISHER.subscribe(self._listener, RideTestMessageWithAttrs)
     PUBLISHER.unsubscribe(self._listener, RideTestMessageWithAttrs)
     msg_obj = RideTestMessageWithAttrs(foo='one', bar='two')
     msg_obj.publish()
     assert_equal(self._msg, '')
 def test_publishing_ride_message_from_msg_obj(self):
     PUBLISHER.subscribe(self._listener, RideMessage)
     msg_obj = RideMessage()
     msg_obj.publish()
     assert_equal(self._msg, msg_obj)
 def test_publishing_invalid_topic(self):
     PUBLISHER.subscribe(self._listener, RideMessage)
     assert_raises(TypeError, PUBLISHER.publish, 'RideTestMessageWithAttrs',
                   'content3')
     assert_equal(self._msg, '')
 def test_publishing_ride_message(self):
     PUBLISHER.subscribe(self._listener, RideMessage)
     PUBLISHER.publish(RideTestMessageWithAttrs, 'content3')
     assert_equal(self._msg, 'content3')
 def setUp(self):
     self._msg = ''
     TestPublisher.cls_msg = ''
     TestPublisher.cls_msgs.clear()
     PUBLISHER.unsubscribe_all()
     PUBLISHER._publisher.getTopicMgr().clearTree()
 def __init__(self):
     PUBLISHER.subscribe(self._dummy_listener, RideTestMessageWithAttrs)