def test_simple_dict(self): params = OrderedDict( [('a', 'A'), ] ) result = get_params(params) self.assertEqual(result, namedtuple(TYPE, ('a'))(a='A')) self.assertEqual(result.a, 'A')
def test_empty_dict(self): params = OrderedDict() result = get_params(params) self.assertEqual(result, namedtuple(TYPE, ())()) with self.assertRaises(AttributeError): result.foo
def setUp(self): super(TestFindItem, self).setUp() params = OrderedDict( [ ('a', [OrderedDict([('key', 'KEY1'), ('value', 'VALUE1'), ]), OrderedDict([('key', 'KEY2'), ('value', 'VALUE2'), ]), ]), ] ) self.d = get_params(params) self.a_type = namedtuple(TYPE, ('key', 'value')) self.assertEqual(self.d, namedtuple(TYPE, ('a'))(a=[self.a_type(key='KEY1', value='VALUE1'), self.a_type(key='KEY2', value='VALUE2')]))
def test_nested_list(self): params = [ OrderedDict([('a', 'A0'), ]), OrderedDict([('a', 'A1'), ]), 'B', ] result = get_params(params) a_type = namedtuple(TYPE, ('a')) self.assertEqual(result, [a_type(a='A0'), a_type(a='A1'), 'B']) self.assertEqual(result[0].a, 'A0') self.assertEqual(result[1].a, 'A1') self.assertEqual(result[2], 'B')
def main(): try: rospy.init_node(NODE_NAME) logger.warnf('Start test node : {}', NODE_NAME) topic = find_item( get_params(rospy.get_param("~")).ros.topics, 'key', 'gopigo') pub = rospy.Publisher(topic.name, Twist, queue_size=1) r = rospy.Rate(2) twist = Twist() twist.linear.x = 0.8 twist.angular.z = 0.5 while not rospy.is_shutdown(): pub.publish(twist) r.sleep() except rospy.ROSInterruptException: pass
def test_complex(self): params = OrderedDict( [ ('a', 'A'), ('b', [ OrderedDict([('ba', 'bA0'), ('bb', 'bB0'), ]), OrderedDict([('ba', 'bA1'), ('bb', 'bB1'), ]), ]), ] ) result = get_params(params) b_type = namedtuple(TYPE, ('ba', 'bb')) self.assertEqual(result, namedtuple(TYPE, ('a', 'b')) (a='A', b=[b_type(ba='bA0', bb='bB0'), b_type(ba='bA1', bb='bB1')])) self.assertEqual(result.a, 'A') self.assertEqual(result.b[0].ba, 'bA0') self.assertEqual(result.b[0].bb, 'bB0') self.assertEqual(result.b[1].ba, 'bA1') self.assertEqual(result.b[1].bb, 'bB1')
def test_nested_dict(self): params = OrderedDict( [ ('a', OrderedDict( [ ('aa', 'aA'), ('ab', OrderedDict([('aba', 'abA'), ])), ] )), ('b', 'B'), ] ) result = get_params(params) ab = namedtuple(TYPE, ('aba'))(aba='abA') a = namedtuple(TYPE, ('aa', 'ab'))(aa='aA', ab=ab) self.assertEqual(result, namedtuple(TYPE, ('a', 'b'))(a=a, b='B')) self.assertEqual(result.a.aa, 'aA') self.assertEqual(result.a.ab.aba, 'abA') self.assertEqual(result.b, 'B')
def __init__(self, node_name): self.node_name = node_name self._params = get_params(rospy.get_param('~')) self.__client = mqtt.Client(protocol=mqtt.MQTTv311) self.__client.on_connect = self._on_connect self.__client.on_message = self._on_message rospy.on_shutdown(self._do_stop) rospy.on_shutdown(self.__client.disconnect) rospy.on_shutdown(self.__client.loop_stop) self.__ros_pub = rospy.Publisher(find_item(self._params.ros.topics, 'key', 'gopigo').name, Twist, queue_size=1) self.__moving = False self.__lock = threading.Lock() self._cmd_payload_re = re.compile( find_item(self._params.mqtt.topics, 'key', 'fiware2gopigo').re)
def test_simple_list(self): result = get_params(['a', 'b']) self.assertEqual(result, ['a', 'b'])
def __init__(self, node_name): self.node_name = node_name self._params = get_params(rospy.get_param('~')) rospy.Subscriber( find_item(self._params.ros.topics, 'key', 'gopigo').name, Twist, self._on_receive)