コード例 #1
0
    def test_get_publisher_unknown(self):
        topic = 'unknown_type'
        topic_type_str = self.topics_and_types[topic]

        pub_map = LanguageToMessageTranslator.get_publisher(
            topic, topic_type_str)

        self.assertIsNotNone(pub_map)
        self.assertEqual(0, len(pub_map))
コード例 #2
0
    def test_parse_command_map_unknown_type(self):
        # Same as above, use an unknown message type
        topic = 'unknown_type'
        topic_type_str = self.topics_and_types[topic]
        commands = self.params[topic]
        ret = LanguageToMessageTranslator.parse_command_mapping(
            topic, topic_type_str, commands)

        self.assertIsNotNone(ret)
        self.assertEqual({}, ret)
コード例 #3
0
    def test_get_publisher_float(self):
        topic = 'not/a/global/topic'
        topic_type_str = self.topics_and_types[topic]

        pub_map = LanguageToMessageTranslator.get_publisher(
            topic, topic_type_str)

        self.assertIsNotNone(pub_map)
        self.assertEqual(1, len(pub_map))
        self.assertTrue(topic in pub_map)

        pub = pub_map[topic]
        self.assertIsInstance(pub, rospy.Publisher)
        self.assertEqual('std_msgs/Float32', pub.type)
コード例 #4
0
    def test_parse_command_map_basic(self):
        # Turn the commands defined in 'basic_topic' into a command mapping.
        topic = 'basic_topic'
        topic_type_str = self.topics_and_types[topic]
        commands = self.params[topic]
        ret = LanguageToMessageTranslator.parse_command_mapping(
            topic, topic_type_str, commands)

        self.assertIsNotNone(ret)

        # Should have the same number of elements as commands.
        self.assertEqual(len(commands), len(ret))

        for cmd in commands:  # All commands are in the map
            self.assertIn(cmd, ret)
            # Inspect each tuple: (topic, message)
            x = ret[cmd]
            self.assertEqual(2, len(x))
            self.assertEqual(topic, x[0])
            self.assertIsInstance(x[1], genpy.Message)
            self.assertIsInstance(x[1], std_msgs.msg.String)

        self.assertEqual('output', ret['input'][1].data)
        self.assertEqual('output with spaces', ret['input with spaces'][1].data)
コード例 #5
0
 def test_parse_command_map_wrong_type(self):
     not_a_type = 'NotAType'
     ret = LanguageToMessageTranslator.parse_command_mapping(
         'topic_name', not_a_type, {'a': 'b'})
     self.assertIsNotNone(ret)
コード例 #6
0
 def setupTranslator(self):
     self.translator = LanguageToMessageTranslator()