def test_complex(self): params = OrderedDict([ ('a', 'A'), ('b', [ OrderedDict([ ('ba', 'bA0'), ('bb', 'bB0'), ]), OrderedDict([ ('ba', 'bA1'), ('bb', 'bB1'), ]), ]), ]) result = getParams(params) b_type = namedtuple(GENERIC_DICT, ('ba', 'bb')) self.assertEqual( result, namedtuple(GENERIC_DICT, ('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_simple_dict(self): params = OrderedDict([ ('a', 'A'), ]) result = getParams(params) self.assertEqual(result, namedtuple(GENERIC_DICT, ('a'))(a='A')) self.assertEqual(result.a, 'A')
def test_empty_dict(self): params = OrderedDict() result = getParams(params) self.assertEqual(result, namedtuple(GENERIC_DICT, ())()) with self.assertRaises(AttributeError): result.foo
def main(): try: rospy.init_node(NODE_NAME) logger.warnf('Start test node : {}', NODE_NAME) topic = findItem(getParams(rospy.get_param("~")).ros.topics, 'key', 'temperature') pub = rospy.Publisher(topic.name, Float32, queue_size=10) r = rospy.Rate(2) while not rospy.is_shutdown(): pub.publish(Float32(1.0)) r.sleep() except rospy.ROSInterruptException: pass
def __init__(self, node_name): self.node_name = node_name self.__client = mqtt.Client(protocol=mqtt.MQTTv311) self.__client.on_connect = self._on_connect rospy.on_shutdown(self.__client.disconnect) rospy.on_shutdown(self.__client.loop_stop) self._params = getParams(rospy.get_param("~")) topic = findItem(self._params.ros.topics, 'key', 'temperature') self.__ros_sub = rospy.Subscriber(topic.name, Float32, self._on_receive, queue_size=10)
def test_nested_list(self): params = [ OrderedDict([ ('a', 'A0'), ]), OrderedDict([ ('a', 'A1'), ]), 'B', ] result = getParams(params) a_type = namedtuple(GENERIC_DICT, ('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 __init__(self, node_name): self.node_name = node_name 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._params = getParams(rospy.get_param("~")) topic = findItem(self._params.ros.topics, 'key', 'turtlesim') self.__ros_pub = rospy.Publisher(topic.name, Twist, queue_size=10) self.__do_move = False self.__lock = threading.Lock() self._cmd_payload_re = re.compile( findItem(self._params.mqtt.topics, 'key', 'command_sender').re)
def test_nested_dict(self): params = OrderedDict([ ('a', OrderedDict([ ('aa', 'aA'), ('ab', OrderedDict([ ('aba', 'abA'), ])), ])), ('b', 'B'), ]) result = getParams(params) ab = namedtuple(GENERIC_DICT, ('aba'))(aba='abA') a = namedtuple(GENERIC_DICT, ('aa', 'ab'))(aa='aA', ab=ab) self.assertEqual(result, namedtuple(GENERIC_DICT, ('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 setUp(self): super(TestFindItem, self).setUp() params = OrderedDict([ ('a', [ OrderedDict([ ('key', 'KEY1'), ('value', 'VALUE1'), ]), OrderedDict([ ('key', 'KEY2'), ('value', 'VALUE2'), ]), ]), ]) self.d = getParams(params) self.a_type = namedtuple(GENERIC_DICT, ('key', 'value')) self.assertEqual( self.d, namedtuple(GENERIC_DICT, ('a'))(a=[ self.a_type(key='KEY1', value='VALUE1'), self.a_type(key='KEY2', value='VALUE2') ]))
def test_simple_list(self): result = getParams(['a', 'b']) self.assertEqual(result, ['a', 'b'])