41 from rostopic
import _str_plot_fields
42 from std_msgs.msg
import String
43 from test_rostopic.msg
import Arrays, Embed, Simple, TVals
45 from genpy
import Time, Duration
46 from rostopic
import create_field_filter
50 rospy.rostime.set_rostime_initialized(
True)
51 rospy.rostime._set_rostime(Time(0, 1234))
55 simple_v = Simple(1, -2, 3, -4,
'a', 7, 8, 9,
'bar')
56 simple_d =
'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64,field.str' 57 simple_nostr =
'time,field.b,field.int16,field.int32,field.int64,field.c,field.uint16,field.uint32,field.uint64' 59 arrays_v = Arrays([-1], chr(2)+chr(3), [3, 4, 5], [6, 7, 8], [
'a1',
'b2',
'b3'], [Time(123, 456), Time(78, 90)])
60 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' 61 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' 63 embed_v = Embed(simple_v, arrays_v)
64 embed_d = simple_d.replace(
'field.',
'field.simple.')+
','+arrays_d.replace(
'field.',
'field.arrays.')[5:]
65 embed_nostr = simple_nostr.replace(
'field.',
'field.simple.')+
','+arrays_nostr.replace(
'field.',
'field.arrays.')[5:]
66 embed_noarr = simple_d.replace(
'field.',
'field.simple.')
67 embed_nostr_noarr = simple_nostr.replace(
'field.',
'field.simple.')
70 f = create_field_filter(echo_nostr=
False, echo_noarr=
False)
72 self.assertEquals(
"time,field.data", _str_plot_fields(m,
'field', f))
74 self.assertEquals(
'time,field.data', _str_plot_fields(m,
'field', f))
75 m = TVals(Time(123, 456), Duration(78, 90))
76 v = _str_plot_fields(m,
'field', f)
77 self.assertEquals(
'time,field.t,field.d', v)
79 self.assertEquals(simple_d, _str_plot_fields(m,
'field', f))
81 self.assertEquals(arrays_d, _str_plot_fields(m,
'field', f))
83 self.assertEquals(embed_d, _str_plot_fields(m,
'field', f))
85 f = create_field_filter(echo_nostr=
True, echo_noarr=
False)
87 self.assertEquals(
"time,", _str_plot_fields(m,
'field', f))
89 self.assertEquals(
'time,', _str_plot_fields(m,
'field', f))
90 m = TVals(Time(123, 456), Duration(78, 90))
91 v = _str_plot_fields(m,
'field', f)
92 self.assertEquals(
'time,field.t,field.d', v)
94 self.assertEquals(simple_nostr, _str_plot_fields(m,
'field', f))
96 self.assertEquals(arrays_nostr, _str_plot_fields(m,
'field', f))
98 self.assertEquals(embed_nostr, _str_plot_fields(m,
'field', f))
100 f = create_field_filter(echo_nostr=
False, echo_noarr=
True)
102 self.assertEquals(
"time,field.data", _str_plot_fields(m,
'field', f))
104 self.assertEquals(
"time,field.data", _str_plot_fields(m,
'field', f))
105 m = TVals(Time(123, 456), Duration(78, 90))
106 v = _str_plot_fields(m,
'field', f)
107 self.assertEquals(
'time,field.t,field.d', v)
109 self.assertEquals(simple_d, _str_plot_fields(m,
'field', f))
111 self.assertEquals(
'time,', _str_plot_fields(m,
'field', f))
113 self.assertEquals(embed_noarr, _str_plot_fields(m,
'field', f))
115 f = create_field_filter(echo_nostr=
True, echo_noarr=
True)
117 self.assertEquals(
"time,", _str_plot_fields(m,
'field', f))
119 self.assertEquals(
'time,', _str_plot_fields(m,
'field', f))
120 m = TVals(Time(123, 456), Duration(78, 90))
121 v = _str_plot_fields(m,
'field', f)
122 self.assertEquals(
'time,field.t,field.d', v)
124 self.assertEquals(simple_nostr, _str_plot_fields(m,
'field', f))
126 self.assertEquals(
'time,', _str_plot_fields(m,
'field', f))
128 self.assertEquals(embed_nostr_noarr, _str_plot_fields(m,
'field', f))
131 from rostopic
import _str_plot
132 from std_msgs.msg
import String
133 from test_rostopic.msg
import Arrays, Embed, Simple, TVals
135 from genpy
import Time, Duration
136 from rostopic
import create_field_filter
140 rospy.rostime.set_rostime_initialized(
True)
141 rospy.rostime._set_rostime(Time(0, 1234))
142 r_time = Time(0, 5678)
145 simple_v = Simple(1, -2, 3, -4,
'a', 7, 8, 9,
'bar')
146 simple_d =
'1234,1,-2,3,-4,a,7,8,9,bar' 147 simple_nostr =
'1234,1,-2,3,-4,a,7,8,9' 149 arrays_v = Arrays([-1], chr(2)+chr(3), [3, 4, 5], [6, 7, 8], [
'a1',
'b2',
'b3'], [Time(123, 456), Time(78, 90)])
150 arrays_d =
'1234,-1,2,3,3,4,5,6,7,8,a1,b2,b3,123000000456,78000000090' 151 arrays_nostr =
'1234,-1,2,3,3,4,5,6,7,8,123000000456,78000000090' 153 embed_v = Embed(simple_v, arrays_v)
154 embed_d = simple_d+
','+arrays_d[5:]
158 self.assertEquals(
'5678,foo', _str_plot(m, current_time=r_time, field_filter=
None))
161 f = create_field_filter(echo_nostr=
False, echo_noarr=
False)
163 self.assertEquals(
"1234,", _str_plot(m, field_filter=f))
165 self.assertEquals(
'1234,foo', _str_plot(m, field_filter=f))
166 m = TVals(Time(123, 456), Duration(78, 90))
167 v = _str_plot(m, field_filter=f)
168 self.assertEquals(
'1234,123000000456,78000000090', v)
170 self.assertEquals(simple_d, _str_plot(m, field_filter=f))
172 self.assertEquals(arrays_d, _str_plot(m, field_filter=f))
174 self.assertEquals(embed_d, _str_plot(m, field_filter=f))
176 f = create_field_filter(echo_nostr=
True, echo_noarr=
False)
178 self.assertEquals(
"1234,", _str_plot(m, field_filter=f))
180 self.assertEquals(
'1234,', _str_plot(m, field_filter=f))
181 m = TVals(Time(123, 456), Duration(78, 90))
182 v = _str_plot(m, field_filter=f)
183 self.assertEquals(
'1234,123000000456,78000000090', v)
185 self.assertEquals(simple_nostr, _str_plot(m, field_filter=f))
187 self.assertEquals(arrays_nostr, _str_plot(m, field_filter=f))
189 self.assertEquals(simple_nostr+arrays_nostr[4:], _str_plot(m, field_filter=f))
191 f = create_field_filter(echo_nostr=
False, echo_noarr=
True)
193 self.assertEquals(
"1234,", _str_plot(m, field_filter=f))
195 self.assertEquals(
'1234,foo', _str_plot(m, field_filter=f))
196 m = TVals(Time(123, 456), Duration(78, 90))
197 v = _str_plot(m, field_filter=f)
198 self.assertEquals(
'1234,123000000456,78000000090', v)
200 self.assertEquals(simple_d, _str_plot(m, field_filter=f))
202 self.assertEquals(
'1234,', _str_plot(m, field_filter=f))
204 self.assertEquals(simple_d, _str_plot(m, field_filter=f))
206 f = create_field_filter(echo_nostr=
True, echo_noarr=
True)
208 self.assertEquals(
"1234,", _str_plot(m, field_filter=f))
210 self.assertEquals(
'1234,', _str_plot(m, field_filter=f))
211 m = TVals(Time(123, 456), Duration(78, 90))
212 v = _str_plot(m, field_filter=f)
213 self.assertEquals(
'1234,123000000456,78000000090', v)
215 self.assertEquals(simple_nostr, _str_plot(m, field_filter=f))
217 self.assertEquals(
'1234,', _str_plot(m, field_filter=f))
219 self.assertEquals(simple_nostr, _str_plot(m, field_filter=f))
226 from std_msgs.msg
import String
227 from test_rostopic.msg
import Arrays, Embed, Simple, TVals
229 from genpy
import Time, Duration
230 from roslib.message
import strify_message
231 from rostopic
import create_field_filter
233 simple_v = Simple(1, -2, 3, -4,
'a', 7, 8, 9,
'bar')
234 simple_d = {
'b': 1,
'int16': -2,
'int32': 3,
'int64': -4,
'c':
'a',
'uint16': 7,
'uint32': 8,
'uint64': 9,
'str':
'bar'}
235 simple_nostr = simple_d.copy()
236 del simple_nostr[
'str']
238 arrays_v = Arrays([-1], chr(2)+chr(3), [3, 4, 5], [6, 7, 8], [
'a1',
'b2',
'b3'], [Time(123, 456), Time(78, 90)])
239 arrays_d = {
'int8_arr': [-1],
'uint8_arr': [2, 3],
'int32_arr': [3, 4, 5],
'uint32_arr': [6, 7, 8],
'string_arr': [
'a1',
'b2',
'b3'],
'time_arr': [{
'secs': 123,
'nsecs': 456}, {
'secs': 78,
'nsecs': 90}]}
240 arrays_nostr = arrays_d.copy()
241 del arrays_nostr[
'string_arr']
243 embed_v = Embed(simple_v, arrays_v)
244 embed_d = {
'simple': simple_d,
'arrays': arrays_d}
246 f = create_field_filter(echo_nostr=
False, echo_noarr=
False)
248 self.assertEquals(
"data: ''", strify_message(m, field_filter=f))
250 self.assertEquals(
'data: "foo"', strify_message(m, field_filter=f))
251 m = TVals(Time(123, 456), Duration(78, 90))
252 v = yaml.load(strify_message(m, field_filter=f))
253 self.assertEquals({
't': {
'secs': 123,
'nsecs': 456},
'd': {
'secs': 78,
'nsecs': 90}}, v)
255 v = yaml.load(strify_message(m, field_filter=f))
256 self.assertEquals(simple_d, v)
258 v = yaml.load(strify_message(m, field_filter=f))
259 self.assertEquals(arrays_d, v)
261 v = yaml.load(strify_message(m, field_filter=f))
262 self.assertEquals(embed_d, v)
264 f = create_field_filter(echo_nostr=
True, echo_noarr=
False)
266 self.assertEquals(
'', strify_message(m, field_filter=f))
268 self.assertEquals(
'', strify_message(m, field_filter=f))
269 m = TVals(Time(123, 456), Duration(78, 90))
270 v = yaml.load(strify_message(m, field_filter=f))
271 self.assertEquals({
't': {
'secs': 123,
'nsecs': 456},
'd': {
'secs': 78,
'nsecs': 90}}, v)
273 v = yaml.load(strify_message(m, field_filter=f))
274 self.assertEquals(simple_nostr, v)
276 v = yaml.load(strify_message(m, field_filter=f))
277 self.assertEquals(arrays_nostr, v)
279 v = yaml.load(strify_message(m, field_filter=f))
280 self.assertEquals({
'simple': simple_nostr,
'arrays': arrays_nostr}, v)
282 f = create_field_filter(echo_nostr=
False, echo_noarr=
True)
284 self.assertEquals(
"data: ''", strify_message(m, field_filter=f))
286 self.assertEquals(
'data: "foo"', strify_message(m, field_filter=f))
287 m = TVals(Time(123, 456), Duration(78, 90))
288 v = yaml.load(strify_message(m, field_filter=f))
289 self.assertEquals({
't': {
'secs': 123,
'nsecs': 456},
'd': {
'secs': 78,
'nsecs': 90}}, v)
291 v = yaml.load(strify_message(m, field_filter=f))
292 self.assertEquals(simple_d, v)
294 v = yaml.load(strify_message(m, field_filter=f))
295 self.assertEquals(
None, v)
297 v = yaml.load(strify_message(m, field_filter=f))
298 self.assertEquals({
'simple': simple_d,
'arrays':
None}, v)
300 f = create_field_filter(echo_nostr=
True, echo_noarr=
True)
302 self.assertEquals(
'', strify_message(m, field_filter=f))
304 self.assertEquals(
'', strify_message(m, field_filter=f))
305 m = TVals(Time(123, 456), Duration(78, 90))
306 v = yaml.load(strify_message(m, field_filter=f))
307 self.assertEquals({
't': {
'secs': 123,
'nsecs': 456},
'd': {
'secs': 78,
'nsecs': 90}}, v)
309 v = yaml.load(strify_message(m, field_filter=f))
310 self.assertEquals(simple_nostr, v)
312 v = yaml.load(strify_message(m, field_filter=f))
313 self.assertEquals({
'simple': simple_nostr,
'arrays':
None}, v)
316 from std_msgs.msg
import Header, Int32, String
317 from test_rostopic.msg
import Arrays, Embed, Floats, Simple, TVals
319 from rostopic
import create_field_filter
320 f = create_field_filter(echo_nostr=
False, echo_noarr=
False)
322 self.assertEquals([
'data'], list(f(m)))
324 self.assertEquals([
'data'], list(f(m)))
326 self.assertEquals([
'int8_arr',
'uint8_arr',
'int32_arr',
'uint32_arr',
'string_arr',
'time_arr'], list(f(m)))
328 self.assertEquals([
'simple',
'arrays'], list(f(m)))
330 self.assertEquals([
'b',
'int16',
'int32',
'int64',
'c',
'uint16',
'uint32',
'uint64',
'str'], list(f(m)))
332 self.assertEquals([
'float32',
'float64'], list(f(m)))
334 self.assertEquals([
't',
'd'], list(f(m)))
336 self.assertEquals([
'seq',
'stamp',
'frame_id'], list(f(m)))
338 f = create_field_filter(echo_nostr=
True, echo_noarr=
False)
340 self.assertEquals([], list(f(m)))
342 self.assertEquals([
'data'], list(f(m)))
344 self.assertEquals([
'int8_arr',
'uint8_arr',
'int32_arr',
'uint32_arr',
'time_arr'], list(f(m)))
346 self.assertEquals([
'simple',
'arrays'], list(f(m)))
348 self.assertEquals([
'b',
'int16',
'int32',
'int64',
'c',
'uint16',
'uint32',
'uint64'], list(f(m)))
350 self.assertEquals([
'float32',
'float64'], list(f(m)))
352 self.assertEquals([
't',
'd'], list(f(m)))
354 self.assertEquals([
'seq',
'stamp'], list(f(m)))
356 f = create_field_filter(echo_nostr=
False, echo_noarr=
True)
358 self.assertEquals([
'data'], list(f(m)))
360 self.assertEquals([
'data'], list(f(m)))
362 self.assertEquals([], list(f(m)))
364 self.assertEquals([
'simple',
'arrays'], list(f(m)))
366 self.assertEquals([
'b',
'int16',
'int32',
'int64',
'c',
'uint16',
'uint32',
'uint64',
'str'], list(f(m)))
368 self.assertEquals([
'float32',
'float64'], list(f(m)))
370 self.assertEquals([
't',
'd'], list(f(m)))
372 self.assertEquals([
'seq',
'stamp',
'frame_id'], list(f(m)))
374 f = create_field_filter(echo_nostr=
True, echo_noarr=
True)
376 self.assertEquals([], list(f(m)))
378 self.assertEquals([
'data'], list(f(m)))
380 self.assertEquals([], list(f(m)))
382 self.assertEquals([
'simple',
'arrays'], list(f(m)))
384 self.assertEquals([
'b',
'int16',
'int32',
'int64',
'c',
'uint16',
'uint32',
'uint64'], list(f(m)))
386 self.assertEquals([
'float32',
'float64'], list(f(m)))
388 self.assertEquals([
't',
'd'], list(f(m)))
390 self.assertEquals([
'seq',
'stamp'], list(f(m)))
393 from test_rostopic.msg
import ArrayVal, Val
394 from rostopic
import msgevalgen
as f
398 for v
in [
'ABCDEFG',
'abcdefg',
'1234567',
'short']:
399 msg.vals.append(Val(val=v))
401 self.assertEqual(f(
''),
None)
402 self.assertEqual(f(
'/'),
None)
403 self.assertListEqual(f(
'/vals')(msg), msg.vals)
404 self.assertListEqual(f(
'/vals/')(msg), msg.vals)
406 self.assertListEqual(f(
'/vals[:]')(msg), msg.vals)
407 self.assertListEqual(f(
'/vals[0:2]')(msg), msg.vals[0:2])
409 self.assertEqual(f(
'/vals[0]')(msg), msg.vals[0])
410 self.assertEqual(f(
'/vals[1]')(msg), msg.vals[1])
411 self.assertEqual(f(
'/vals['),
None)
412 self.assertEqual(f(
'/vals[]'),
None)
413 self.assertEqual(f(
'/vals[0'),
None)
415 self.assertEqual(f(
'/vals[0]/val')(msg), msg.vals[0].val)
416 self.assertEqual(f(
'/vals[1]/val')(msg), msg.vals[1].val)
417 self.assertEqual(f(
'/vals[/val'),
None)
418 self.assertEqual(f(
'/vals[]/val'),
None)
419 self.assertEqual(f(
'/vals[0/val'),
None)
421 self.assertEqual(f(
'/vals[0]/val[:]')(msg), msg.vals[0].val)
422 self.assertEqual(f(
'/vals[0]/val[0:2]')(msg), msg.vals[0].val[0:2])
423 self.assertEqual(f(
'/vals[0]/val[:-3]')(msg), msg.vals[0].val[:-3])
424 self.assertEqual(f(
'/vals[0]/val[2]')(msg), msg.vals[0].val[2])
426 self.assertListEqual(f(
'/vals[:3]/val[0]')(msg), [
'A',
'a',
'1'])
427 self.assertListEqual(f(
'/vals[:3]/val[0]')(msg), [
'A',
'a',
'1'])
428 self.assertListEqual(f(
'/vals[1:3]/val[0]')(msg), [
'a',
'1'])
429 self.assertListEqual(f(
'/vals[:]/val[-1]')(msg), [
'G',
'g',
'7',
't'])
431 self.assertListEqual(f(
'/vals[:3]/val[1:3]')(msg), [
'BC',
'bc',
'23'])
433 self.assertEqual(f(
'/vals[5]/val')(msg),
None)
434 self.assertListEqual(f(
'/vals[:]/val[6]')(msg), [
'G',
'g',
'7',
None])
436 self.assertEqual(f(
'/vals[:]/val[]'),
None)
437 self.assertEqual(f(
'/unknown[:]/val[0]')(msg),
None)
438 self.assertListEqual(f(
'/vals[:]/unknown[0]')(msg), [
None,
None,
None,
None])
439 self.assertEqual(f(
'/vals/unknown[0]')(msg),
None)
def test_strify_message(self)
def test_sub_str_plot_fields(self)
def test_create_field_filter(self)