36 roslib.load_manifest(
'joy')
45 import rosbagmigration
48 from cStringIO
import StringIO
55 migrator = rosbagmigration.MessageMigrator()
59 return struct.unpack(
'<f',struct.pack(
'<f',x))[0]
69 joy_classes = self.load_saved_classes(
'Joy.saved')
70 joy = joy_classes[
'joy/Joy']
71 return joy([0.1,0.2,0.3,0.4,0.5],[0,1,0,1,0])
74 from sensor_msgs.msg
import Joy
75 from roslib.msg
import Header
76 return Joy(
Header(),[0.1,0.2,0.3,0.4,0.5],[0,1,0,1,0])
80 self.do_test(
'joy', self.get_old_joy, self.get_new_joy)
85 self.pkg_dir = roslib.packages.get_pkg_dir(
"joy")
89 f = open(
"%s/test/saved/%s"%(self.pkg_dir,saved_msg),
'r') 91 type_line = f.readline() 92 pat = re.compile(r"\[(.*)]:")
93 type_match = pat.match(type_line)
95 self.assertTrue(type_match
is not None,
"Full definition file malformed. First line should be: '[my_package/my_msg]:'")
97 saved_type = type_match.groups()[0]
98 saved_full_text = f.read()
100 saved_classes = roslib.genpy.generate_dynamic(saved_type,saved_full_text)
102 self.assertTrue(saved_classes
is not None,
"Could not generate class from full definition file.")
103 self.assertTrue(saved_classes.has_key(saved_type),
"Could not generate class from full definition file.")
109 oldbag =
"%s/test/%s_old.bag"%(self.pkg_dir,name)
110 newbag =
"%s/test/%s_new.bag"%(self.pkg_dir,name)
113 bag = rosbag.Bag(oldbag,
'w')
114 bag.write(
"topic", old_msg(), roslib.rostime.Time())
118 res = rosbagmigration.checkbag(migrator, oldbag)
119 self.assertTrue(
not False in [m[1] == []
for m
in res],
'Bag not ready to be migrated')
120 res = rosbagmigration.fixbag(migrator, oldbag, newbag)
121 self.assertTrue(res,
'Bag not converted successfully')
124 topic, msg, t = rosbag.Bag(newbag).read_messages().next()
130 m.deserialize(buff.getvalue())
133 self.assertTrue(roslib.message.strify_message(msg) == roslib.message.strify_message(m))
141 if __name__ ==
'__main__':
142 rostest.unitrun(
'test_joy_msg',
'test_joy_msg_migration', TestJoyMsgsMigration, sys.argv)
def load_saved_classes(self, saved_msg)
def get_old_joy(self)
Joy ###############.
def setUp(self)
Helper functions ###########.
def do_test(self, name, old_msg, new_msg)