39 from cStringIO
import StringIO
41 from io
import BytesIO
as StringIO
46 from roslib.message
import SerializationError
51 from test_rospy.msg
import PythonKeyword
56 self.assertEquals(PythonKeyword._md5sum,
"1330d6bbfad8e75334346fec949d5133")
67 blank.deserialize(b.getvalue())
69 self.assertEquals(orig, blank, str(orig)+
" != "+str(blank))
71 self.assertAlmostEquals(orig.data, blank.data, 5)
75 from test_rospy.msg
import TransitiveImport
76 m = TransitiveImport()
84 from test_rospy.msg
import TestFixedArray
86 self.assertEquals([0.], m.f32_1)
87 self.assertEquals([0., 0., 0.], m.f32_3)
88 self.assertEquals([0.], m.f64_1)
89 self.assertEquals([0., 0., 0.], m.f64_3)
90 self.assertEquals([0], m.i8_1)
91 self.assertEquals([0, 0, 0], m.i8_3)
92 self.assertEquals(chr(0), m.u8_1)
93 self.assertEquals(chr(0)*3, m.u8_3)
94 self.assertEquals([0], m.i32_1)
95 self.assertEquals([0, 0, 0], m.i32_3)
96 self.assertEquals([0], m.u32_1)
97 self.assertEquals([0, 0, 0], m.u32_3)
98 self.assertEquals([
''], m.s_1)
99 self.assertEquals([
'',
'',
''], m.s_3)
103 m = TestFixedArray(i32_1 = [1])
106 self.assertEquals((1,), c.i32_1)
108 m = TestFixedArray(i32_3 = [-3, 2, 10])
111 self.assertEquals((-3, 2, 10), c.i32_3)
113 m = TestFixedArray(u32_1 = [1234])
116 self.assertEquals((1234,), c.u32_1)
118 m = TestFixedArray(u32_3 = [3, 2, 10])
121 self.assertEquals((3, 2, 10), c.u32_3)
124 m,c = TestFixedArray(f32_1 = [2.]), TestFixedArray()
126 self.assertEquals((2.,), c.f32_1)
128 m,c = TestFixedArray(f32_3 = [1., 2., 3.]), TestFixedArray()
130 self.assertEquals((1., 2., 3.), c.f32_3)
132 m,c = TestFixedArray(u8_1 =
'x'), TestFixedArray()
134 self.assertEquals(
'x', c.u8_1)
136 m,c = TestFixedArray(u8_3 =
'xyz'), TestFixedArray()
138 self.assertEquals(
'xyz', c.u8_3)
140 m,c = TestFixedArray(s_1 = [
'']), TestFixedArray()
142 self.assertEquals([
''], c.s_1)
144 m,c = TestFixedArray(s_1 = [
'blah blah blah']), TestFixedArray()
146 self.assertEquals([
'blah blah blah',], c.s_1)
148 m = TestFixedArray(s_3 = [
'',
'x',
'xyz'])
151 self.assertEquals([
'',
'x',
'xyz'], c.s_3)
153 for v
in [
True,
False]:
154 m = TestFixedArray(b_1 = [v])
157 self.assertEquals([v], c.b_1)
159 m = TestFixedArray(b_3 = [
True,
False,
True])
162 self.assertEquals([
True,
False,
True], c.b_3)
167 from test_rospy.msg
import TestConstants
168 self.assertEquals(-123.0, TestConstants.A)
169 self.assertEquals(124.0, TestConstants.B)
170 self.assertEquals(125.0, TestConstants.C)
171 self.assertEquals(123, TestConstants.X)
172 self.assertEquals(-123, TestConstants.Y)
173 self.assertEquals(124, TestConstants.Z)
174 self.assertEquals(
"'hi", TestConstants.SINGLEQUOTE)
175 self.assertEquals(
'"hello" there', TestConstants.DOUBLEQUOTE)
176 self.assertEquals(
'"hello" \'goodbye\'', TestConstants.MULTIQUOTE)
177 self.assertEquals(
'foo', TestConstants.FOO)
178 self.assertEquals(
'"#comments" are ignored, and leading and trailing whitespace removed',TestConstants.EXAMPLE)
179 self.assertEquals(
'strip', TestConstants.WHITESPACE)
180 self.assertEquals(
'', TestConstants.EMPTY)
182 self.assertEquals(
True, TestConstants.TRUE)
183 self.assertEquals(
False, TestConstants.FALSE)
187 self.assertEquals(Empty(), Empty())
192 self.assertEquals(Bool(), Bool())
195 self.assertEquals(
False, Bool().data)
197 for v
in [
True,
False]:
198 self.assertEquals(Bool(v), Bool(v))
199 self.assertEquals(Bool(v), Bool(data=v))
200 self.assertEquals(Bool(data=v), Bool(data=v))
201 self.assertNotEquals(Bool(
True), Bool(
False))
209 Bool(
True).serialize(b)
210 blank.deserialize(b.getvalue())
211 self.assert_(blank.data)
212 self.assert_(type(blank.data) == bool)
215 Bool(
True).serialize(b)
216 blank.deserialize(b.getvalue())
217 self.assert_(blank.data)
218 self.assert_(type(blank.data) == bool)
223 self.assertEquals(String(), String())
224 self.assertEquals(
'', String().data)
226 self.assertEquals(String(
''), String())
227 self.assertEquals(String(
''), String(
''))
228 self.assertEquals(String(
'foo'), String(
'foo'))
229 self.assertEquals(String(
'foo'), String(data=
'foo'))
230 self.assertEquals(String(data=
'foo'), String(data=
'foo'))
232 self.assertNotEquals(String(
'foo'), String(
'bar'))
233 self.assertNotEquals(String(
'foo'), String(data=
'bar'))
234 self.assertNotEquals(String(data=
'foo'), String(data=
'bar'))
241 for cls
in [Int8, Int16, Int32, Int64]:
242 v = random.randint(1, 127)
243 self.assertEquals(cls(), cls())
244 self.assertEquals(0, cls().data)
245 self.assertEquals(cls(), cls(0))
246 self.assertEquals(cls(0), cls(0))
247 self.assertEquals(cls(v), cls(v))
248 self.assertEquals(cls(-v), cls(-v))
249 self.assertEquals(cls(v), cls(data=v))
250 self.assertEquals(cls(data=v), cls(data=v))
252 self.assertNotEquals(cls(v), cls())
253 self.assertNotEquals(cls(data=v), cls(data=-v))
254 self.assertNotEquals(cls(data=v), cls(data=v-1))
255 self.assertNotEquals(cls(data=v), cls(v-1))
256 self.assertNotEquals(cls(v), cls(v-1))
264 widths = [(8, Int8), (16, Int16), (32, Int32), (64, Int64)]
265 for w, cls
in widths:
266 maxp = long(math.pow(2, w-1)) - 1
267 maxn = -long(math.pow(2, w-1)) + 1
271 cls(maxp+1)._check_types()
272 self.fail(
"check_types should have noted width error[%s]: %s, %s"%(w, maxp+1, cls.__name__))
273 except SerializationError:
pass 275 cls(maxn-1)._check_types()
276 self.fail(
"check_types should have noted width error[%s]: %s, %s"%(w, maxn-1, cls.__name__))
277 except SerializationError:
pass 281 for cls
in [UInt8, UInt16, UInt32, UInt64]:
282 v = random.randint(1, 127)
283 self.assertEquals(cls(), cls())
284 self.assertEquals(0, cls().data)
285 self.assertEquals(cls(), cls(0))
286 self.assertEquals(cls(0), cls(0))
287 self.assertEquals(cls(v), cls(v))
288 self.assertEquals(cls(v), cls(data=v))
289 self.assertEquals(cls(data=v), cls(data=v))
291 self.assertNotEquals(cls(v), cls())
292 self.assertNotEquals(cls(data=v), cls(data=-v))
293 self.assertNotEquals(cls(data=v), cls(data=v-1))
294 self.assertNotEquals(cls(data=v), cls(v-1))
295 self.assertNotEquals(cls(v), cls(v-1))
302 cls(-1)._check_types()
303 self.fail(
"check_types should have noted sign error[%s]: %s"%(w, cls.__name__))
304 except SerializationError:
pass 307 widths = [(8, UInt8), (16, UInt16), (32, UInt32), (64, UInt64)]
308 for w, cls
in widths:
309 maxp = long(math.pow(2, w)) - 1
312 cls(maxp+1)._check_types()
313 self.fail(
"check_types should have noted width error[%s]: %s, %s"%(w, maxp+1, cls.__name__))
314 except SerializationError:
pass 318 for cls
in [Float32, Float64]:
319 self.assertEquals(cls(), cls())
320 self.assertEquals(0., cls().data)
321 self.assertEquals(cls(), cls(0.))
322 self.assertEquals(cls(0.), cls(0.))
323 self.assertEquals(cls(1.), cls(1.))
324 self.assertEquals(cls(1.), cls(data=1.))
325 self.assertEquals(cls(data=1.), cls(data=1.))
326 self.assertEquals(cls(math.pi), cls(math.pi))
327 self.assertEquals(cls(math.pi), cls(data=math.pi))
328 self.assertEquals(cls(data=math.pi), cls(data=math.pi))
330 self.assertNotEquals(cls(1.), cls())
331 self.assertNotEquals(cls(math.pi), cls())
332 self.assertNotEquals(cls(data=math.pi), cls(data=-math.pi))
333 self.assertNotEquals(cls(data=math.pi), cls(data=math.pi-1))
334 self.assertNotEquals(cls(data=math.pi), cls(math.pi-1))
335 self.assertNotEquals(cls(math.pi), cls(math.pi-1))
344 from std_msgs.msg import Int32MultiArray, MultiArrayDimension, MultiArrayLayout, UInt8MultiArray
346 dims = [MultiArrayDimension(
'foo', 1, 2), MultiArrayDimension(
'bar', 3, 4),\
347 MultiArrayDimension(
'foo2', 5, 6), MultiArrayDimension(
'bar2', 7, 8)]
349 self.assertEquals(d, d)
354 self.assertEquals(UInt8MultiArray(),UInt8MultiArray())
355 self.assertEquals(
'',UInt8MultiArray().data)
356 UInt8MultiArray().serialize(buff)
357 self.assertEquals(UInt8MultiArray(layout=MultiArrayLayout()),UInt8MultiArray())
358 UInt8MultiArray(layout=MultiArrayLayout()).serialize(buff)
359 data =
''.join([chr(i)
for i
in range(0, 100)])
360 v = UInt8MultiArray(data=data)
363 self.assertEquals(Int32MultiArray(),Int32MultiArray())
364 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout()),Int32MultiArray())
365 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(), data=[1, 2, 3]),Int32MultiArray(data=[1, 2, 3]))
366 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(), data=[1, 2, 3]),\
367 Int32MultiArray(layout=MultiArrayLayout(),data=[1, 2, 3]))
368 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(dim=[]), data=[1, 2, 3]),\
369 Int32MultiArray(layout=MultiArrayLayout(),data=[1, 2, 3]))
370 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout([], 0), data=[1, 2, 3]),\
371 Int32MultiArray(layout=MultiArrayLayout(),data=[1, 2, 3]))
372 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(dim=[], data_offset=0), data=[1, 2, 3]),\
373 Int32MultiArray(layout=MultiArrayLayout(),data=[1, 2, 3]))
374 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(dim=dims, data_offset=0), data=[1, 2, 3]),\
375 Int32MultiArray(layout=MultiArrayLayout(dim=dims),data=[1, 2, 3]))
376 self.assertEquals(Int32MultiArray(layout=MultiArrayLayout(dims, 10), data=[1, 2, 3]),\
377 Int32MultiArray(layout=MultiArrayLayout(dim=dims,data_offset=10),data=[1, 2, 3]))
380 self.assertNotEquals(Int32MultiArray(data=[1, 2, 3]),Int32MultiArray(data=[4,5,6]))
381 self.assertNotEquals(Int32MultiArray(layout=MultiArrayLayout([], 1), data=[1, 2, 3]),\
382 Int32MultiArray(layout=MultiArrayLayout([], 0),data=[1, 2, 3]))
383 self.assertNotEquals(Int32MultiArray(layout=MultiArrayLayout([], 1), data=[1, 2, 3]),\
384 Int32MultiArray(layout=MultiArrayLayout(dim=[]),data=[1, 2, 3]))
385 self.assertNotEquals(Int32MultiArray(layout=MultiArrayLayout(dims, 10), data=[1, 2, 3]),\
386 Int32MultiArray(layout=MultiArrayLayout(dim=dims,data_offset=11),data=[1, 2, 3]))
387 self.assertNotEquals(Int32MultiArray(layout=MultiArrayLayout(dim=dims, data_offset=10), data=[1, 2, 3]),\
388 Int32MultiArray(layout=MultiArrayLayout(dim=dims[1:],data_offset=10),data=[1, 2, 3]))
392 self.
_test_ser_deser(Int32MultiArray(layout=MultiArrayLayout()),Int32MultiArray())
393 self.
_test_ser_deser(Int32MultiArray(data=[1, 2, 3]),Int32MultiArray())
def test_test_rospy_TestFixedArray(self)
def _test_ser_deser(self, orig, blank, float=False)
Utility for testing roundtrip serialization.
def test_std_msgs_empty(self)
def test_std_msgs_Float(self)
def test_std_msgs_UnsignedInt(self)
def test_std_msgs_SignedInt(self)
def test_std_msgs_Bool(self)
def test_test_rospy_TestConstants(self)
def test_PythonKeyword(self)
def test_test_rospy_TransitiveImport(self)
#2133/2152
def test_std_msgs_MultiArray(self)
def test_std_msgs_String(self)