def toMsg(uuid_obj): """Create a UniqueID message from a UUID object. :param uuid_obj: standard Python :class:`uuid.UUID` object. :returns: `uuid_msgs/UniqueID`_ message. """ return UniqueID(uuid=uuid_obj.bytes)
def test_three_point_set(self): # test data uuids = [ 'da7c242f-2efe-5175-9961-49cc621b80b9', '812f1c08-a34b-5a21-92b9-18b2b0cf4950', '6f0606f6-a776-5940-b5ea-5e889b32c712' ] latitudes = [30.3840168, 30.3857290, 30.3866750] longitudes = [-97.7282100, -97.7316754, -97.7270967] eastings = [622191.124, 621856.023, 622294.785] northings = [3362024.764, 3362210.790, 3362320.569] points = [] for i in range(len(uuids)): latlon = GeoPoint(latitude=latitudes[i], longitude=longitudes[i]) points.append(WayPoint(id=UniqueID(uuid=uuids[i]), position=latlon)) # test iterator wupts = WuPointSet(points) i = 0 for w in wupts: self.assertEqual(w.uuid(), uuids[i]) self.assertEqual(wupts[uuids[i]].uuid(), uuids[i]) self.assertAlmostEqual(w.utm.easting, eastings[i], places=3) self.assertAlmostEqual(w.utm.northing, northings[i], places=3) point_xy = w.toPointXY() self.assertAlmostEqual(point_xy.x, eastings[i], places=3) self.assertAlmostEqual(point_xy.y, northings[i], places=3) self.assertAlmostEqual(point_xy.z, 0.0, places=3) i += 1 self.assertEqual(i, 3) self.assertEqual(len(wupts), 3) bogus = '00000000-c433-5c42-be2e-fbd97ddff9ac' self.assertFalse(bogus in wupts) self.assertEqual(wupts.get(bogus), None) uu = uuids[1] self.assertTrue(uu in wupts) wpt = wupts[uu] self.assertEqual(wpt.uuid(), uu) self.assertNotEqual(wupts.get(uu), None) self.assertEqual(wupts.get(uu).uuid(), uu) # test index() function for i in xrange(len(uuids)): self.assertEqual(wupts.index(uuids[i]), i) self.assertEqual(wupts.points[i].id.uuid, uuids[i])
def test_nil_msg(self): x = UniqueID() y = toMsg(uuid.UUID(hex='00000000-0000-0000-0000-000000000000')) self.assertEqual(x, y)
def test_random_msg(self): x = UniqueID() y = toMsg(fromRandom()) self.assertNotEqual(x, y)