test_occupancygrids.py
Go to the documentation of this file.
1 import unittest
2 import numpy as np
3 import ros_numpy
4 from nav_msgs.msg import OccupancyGrid, MapMetaData
5 
6 from io import BytesIO
7 
8 class TestOccupancyGrids(unittest.TestCase):
9  def test_masking(self):
10  data = -np.ones((30, 30), np.int8)
11  data[10:20, 10:20] = 100
12 
13  msg = ros_numpy.msgify(OccupancyGrid, data)
14 
15  data_out = ros_numpy.numpify(msg)
16 
17  self.assertIs(data_out[5, 5], np.ma.masked)
18  np.testing.assert_equal(data_out[10:20, 10:20], 100)
19 
20  def test_serialization(self):
21  msg = OccupancyGrid(
22  info=MapMetaData(
23  width=3,
24  height=3
25  ),
26  data = [0, 0, 0, 0, -1, 0, 0, 0, 0]
27  )
28 
29  data = ros_numpy.numpify(msg)
30  self.assertIs(data[1,1], np.ma.masked)
31  msg2 = ros_numpy.msgify(OccupancyGrid, data)
32 
33  self.assertEqual(msg.info, msg2.info)
34 
35  io1 = BytesIO()
36  io2 = BytesIO()
37  msg.serialize(io1)
38  msg2.serialize(io2)
39 
40  self.assertEqual(io1.getvalue(), io2.getvalue(), "Message serialization survives round-trip")
41 
42 if __name__ == '__main__':
43  unittest.main()


ros_numpy
Author(s): Eric Wieser
autogenerated on Sat Oct 3 2020 03:25:57