def test_sub_str_plot_fields(self): from rostopic import _str_plot_fields from std_msgs.msg import String, Int32, Header from test_rostopic.msg import Simple, TVals, Floats, Arrays, Embed from roslib.rostime import Time, Duration from rostopic import create_field_filter # str plotting requires rospy time, we fix time to a set time import rospy.rostime rospy.rostime.set_rostime_initialized(True) rospy.rostime._set_rostime(Time(0, 1234)) r_time = Time(0, 5678) # prepare test values simple_v = Simple(1, -2, 3, -4, 'a', 7, 8, 9, 'bar') simple_d = 'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64,field.str' simple_nostr = 'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64' arrays_v = Arrays([-1], chr(2) + chr(3), [3, 4, 5], [6, 7, 8], ['a1', 'b2', 'b3'], [Time(123, 456), Time(78, 90)]) arrays_d = 'time,field.int8_arr0,field.uint8_arr0,field.uint8_arr1,field.int32_arr0,field.int32_arr1,field.int32_arr2,field.uint32_arr0,field.uint32_arr1,field.uint32_arr2,field.string_arr0,field.string_arr1,field.string_arr2,field.time_arr0,field.time_arr1' arrays_nostr = 'time,field.int8_arr0,field.uint8_arr0,field.uint8_arr1,field.int32_arr0,field.int32_arr1,field.int32_arr2,field.uint32_arr0,field.uint32_arr1,field.uint32_arr2,field.time_arr0,field.time_arr1' embed_v = Embed(simple_v, arrays_v) embed_d = simple_d.replace('field.', 'field.simple.') + ',' + arrays_d.replace( 'field.', 'field.arrays.')[5:] embed_nostr = simple_nostr.replace( 'field.', 'field.simple.') + ',' + arrays_nostr.replace( 'field.', 'field.arrays.')[5:] embed_noarr = simple_d.replace('field.', 'field.simple.') embed_nostr_noarr = simple_nostr.replace('field.', 'field.simple.') # test over all combinations of field filters f = create_field_filter(echo_nostr=False, echo_noarr=False) m = String() self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,field.data', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_d, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals(arrays_d, _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_d, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=True, echo_noarr=False) m = String() self.assertEquals("time,", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_nostr, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals(arrays_nostr, _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_nostr, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=False, echo_noarr=True) m = String() self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_d, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_noarr, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=True, echo_noarr=True) m = String() self.assertEquals("time,", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_nostr, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_nostr_noarr, _str_plot_fields(m, 'field', f))
def test_sub_str_plot_fields(self): from rostopic import _str_plot_fields from std_msgs.msg import String from test_rostopic.msg import Arrays, Embed, Simple, TVals from genpy import Time, Duration from rostopic import create_field_filter # str plotting requires rospy time, we fix time to a set time import rospy.rostime rospy.rostime.set_rostime_initialized(True) rospy.rostime._set_rostime(Time(0, 1234)) Time(0, 5678) # prepare test values simple_v = Simple(1, -2, 3, -4, 'a', 7, 8, 9, 'bar') simple_d = 'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64,field.str' simple_nostr = 'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64' arrays_v = Arrays([-1], chr(2)+chr(3), [3, 4, 5], [6, 7, 8], ['a1', 'b2', 'b3'], [Time(123, 456), Time(78, 90)]) arrays_d = 'time,field.int8_arr0,field.uint8_arr0,field.uint8_arr1,field.int32_arr0,field.int32_arr1,field.int32_arr2,field.uint32_arr0,field.uint32_arr1,field.uint32_arr2,field.string_arr0,field.string_arr1,field.string_arr2,field.time_arr0,field.time_arr1' arrays_nostr = 'time,field.int8_arr0,field.uint8_arr0,field.uint8_arr1,field.int32_arr0,field.int32_arr1,field.int32_arr2,field.uint32_arr0,field.uint32_arr1,field.uint32_arr2,field.time_arr0,field.time_arr1' embed_v = Embed(simple_v, arrays_v) embed_d = simple_d.replace('field.', 'field.simple.')+','+arrays_d.replace('field.', 'field.arrays.')[5:] embed_nostr = simple_nostr.replace('field.', 'field.simple.')+','+arrays_nostr.replace('field.', 'field.arrays.')[5:] embed_noarr = simple_d.replace('field.', 'field.simple.') embed_nostr_noarr = simple_nostr.replace('field.', 'field.simple.') # test over all combinations of field filters f = create_field_filter(echo_nostr=False, echo_noarr=False) m = String() self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,field.data', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_d, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals(arrays_d, _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_d, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=True, echo_noarr=False) m = String() self.assertEquals("time,", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_nostr, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals(arrays_nostr, _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_nostr, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=False, echo_noarr=True) m = String() self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals("time,field.data", _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_d, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_noarr, _str_plot_fields(m, 'field', f)) f = create_field_filter(echo_nostr=True, echo_noarr=True) m = String() self.assertEquals("time,", _str_plot_fields(m, 'field', f)) m = String('foo') self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = TVals(Time(123, 456), Duration(78, 90)) v = _str_plot_fields(m, 'field', f) self.assertEquals('time,field.t,field.d', v) m = simple_v self.assertEquals(simple_nostr, _str_plot_fields(m, 'field', f)) m = arrays_v self.assertEquals('time,', _str_plot_fields(m, 'field', f)) m = embed_v self.assertEquals(embed_nostr_noarr, _str_plot_fields(m, 'field', f))