Ejemplo n.º 1
0
    def test_invalid_arguments(self):
        proto = Protocol("test_invalid_arguments")
        sub = subscribe.Subscribe(proto)

        msg = {"op": "subscribe", "topic": 3}
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)

        msg = {"op": "subscribe", "topic": "/jon", "type": 3}
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)

        msg = {"op": "subscribe", "topic": "/jon", "throttle_rate": "fast"}
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)

        msg = {
            "op": "subscribe",
            "topic": "/jon",
            "fragment_size": "five cubits"
        }
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)

        msg = {"op": "subscribe", "topic": "/jon", "queue_length": "long"}
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)

        msg = {"op": "subscribe", "topic": "/jon", "compression": 9000}
        self.assertRaises(InvalidArgumentException, sub.subscribe, msg)
Ejemplo n.º 2
0
    def test_subscribe_works(self):
        proto = Protocol("test_subscribe_works")
        sub = subscribe.Subscribe(proto)
        topic = "/test_subscribe_works"
        msg = String()
        msg.data = "test test_subscribe_works works"
        msg_type = "std_msgs/String"

        received = {"msg": None}

        def send(outgoing):
            received["msg"] = outgoing

        proto.send = send

        sub.subscribe(
            loads(dumps({
                "op": "subscribe",
                "topic": topic,
                "type": msg_type
            })))

        p = rospy.Publisher(topic, String)
        time.sleep(0.25)
        p.publish(msg)

        time.sleep(0.25)
        self.assertEqual(received["msg"]["msg"]["data"], msg.data)
Ejemplo n.º 3
0
 def test_missing_arguments(self):
     proto = Protocol("test_missing_arguments")
     sub = subscribe.Subscribe(proto)
     msg = {"op": "subscribe"}
     self.assertRaises(MissingArgumentException, sub.subscribe, msg)