def do_test(self, name, old_msg, new_msg): # Name the bags oldbag = "%s/test/%s_old.bag"%(self.pkg_dir,name) newbag = "%s/test/%s_new.bag"%(self.pkg_dir,name) # Create an old message bag = rosbag.Bag(oldbag, 'w') bag.write("topic", old_msg(), roslib.rostime.Time()) bag.close() # Check and migrate res = rosbagmigration.checkbag(migrator, oldbag) self.assertTrue(not False in [m[1] == [] for m in res], 'Bag not ready to be migrated') res = rosbagmigration.fixbag(migrator, oldbag, newbag) self.assertTrue(res, 'Bag not converted successfully') # Pull the first message out of the bag topic, msg, t = rosbag.Bag(newbag).read_messages().next() # Reserialize the new message so that floats get screwed up, etc. m = new_msg() buff = StringIO() m.serialize(buff) m.deserialize(buff.getvalue()) # Strifying them helps make the comparison easier until I figure out why the equality operator is failing self.assertTrue(roslib.message.strify_message(msg) == roslib.message.strify_message(m)) # self.assertTrue(msgs[0][1] == m) #Cleanup os.remove(oldbag) os.remove(newbag)
def test_subunmigrated(self): tmp_rule_files = [ 'migrated_explicit_rules.py', 'migrated_mixed_rules.py', 'migrated_addsub_rules.py' ] rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files] inbag = "%s/test/subunmigrated_gen1.bag" % (self.pkg_dir, ) mm = rosbagmigration.MessageMigrator(rule_files, False) res = rosbagmigration.checkbag(mm, inbag) self.assertTrue(len(res[0][1]) == 1) self.assertTrue(not res[0][1][0].valid) self.assertEqual(res[0][1][0].old_class._md5sum, '4b12e5ff694b0e2a31b2ea9e0bd900f4') self.assertEqual(res[0][1][0].new_class._md5sum, 'b5d640967dccef2a24697ec4b8a571ec')
def do_test(self, name, old_msg, new_msg): # Name the bags oldbag = "%s/test/%s_old.bag" % (self.pkg_dir, name) newbag = "%s/test/%s_new.bag" % (self.pkg_dir, name) # Create an old message bag = rosrecord.Rebagger(oldbag) bag.add("topic", old_msg(), roslib.rostime.Time()) bag.close() # Check and migrate res = rosbagmigration.checkbag(oldbag, []) self.assertTrue(res is None or res == [], 'Bag not ready to be migrated') res = rosbagmigration.fixbag(oldbag, newbag, []) self.assertTrue(res, 'Bag not converted successfully') # Pull the first message out of the bag msgs = [msg for msg in rosrecord.logplayer(newbag)] # Reserialize the new message so that floats get screwed up, etc. m = new_msg() buff = StringIO() m.serialize(buff) m.deserialize(buff.getvalue()) #Compare # print "old" # print roslib.message.strify_message(msgs[0][1]) # print "new" # print roslib.message.strify_message(m) # Strifying them helps make the comparison easier until I figure out why the equality operator is failing self.assertTrue( roslib.message.strify_message(msgs[0][1]) == roslib.message.strify_message(m)) # self.assertTrue(msgs[0][1] == m) #Cleanup os.remove(oldbag) os.remove(newbag)
def do_test_constants_rules(self, N): tmp_rule_files = ['constants.bmr'] rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files] inbag = "%s/test/constants_gen%d.bag" % (self.pkg_dir, N) outbag = "%s/test/constants_gen%d.fixed.bag" % (self.pkg_dir, N) mm = rosbagmigration.MessageMigrator(rule_files, False) res = rosbagmigration.checkbag(mm, inbag) self.assertTrue(not False in [m[1] == [] for m in res], 'Bag not ready to be migrated') res = rosbagmigration.fixbag(mm, inbag, outbag) self.assertTrue(res, 'Bag not converted successfully') msgs = [msg for msg in rosrecord.logplayer(outbag)] self.assertTrue(len(msgs) > 0) self.assertEqual(msgs[0][1]._type, 'test_rosbagmigration/Constants', 'Type name is wrong') self.assertEqual(msgs[0][1].value, msgs[0][1].CONSTANT)
def do_test_convergent(self, N): tmp_rule_files = [ 'migrated_explicit_rules.py', 'migrated_mixed_rules.py', 'migrated_addsub_rules.py', 'renamed_rules.py', 'simple_migrated_rules.py', 'converged_rules.py' ] rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files] inbag = "%s/test/convergent_gen%d.bag" % (self.pkg_dir, N) outbag = "%s/test/convergent_gen%d.fixed.bag" % (self.pkg_dir, N) mm = rosbagmigration.MessageMigrator(rule_files, False) res = rosbagmigration.checkbag(mm, inbag) self.assertTrue(not False in [m[1] == [] for m in res], 'Bag not ready to be migrated') res = rosbagmigration.fixbag(mm, inbag, outbag) self.assertTrue(res, 'Bag not converted successfully') msgs = [msg for msg in rosrecord.logplayer(outbag)] self.assertTrue(len(msgs) > 0) self.assertEqual(msgs[0][1]._type, 'test_rosbagmigration/Converged', 'Type name is wrong') self.assertEqual(msgs[0][1].field1[0], struct.unpack('<f', struct.pack('<f', 1.2))[0]) self.assertEqual(msgs[0][1].field1[1], struct.unpack('<f', struct.pack('<f', 3.4))[0]) self.assertEqual(msgs[0][1].field1[2], struct.unpack('<f', struct.pack('<f', 5.6))[0]) self.assertEqual(msgs[0][1].field1[3], struct.unpack('<f', struct.pack('<f', 7.8))[0]) self.assertEqual(msgs[0][1].field2[0].data, 11) self.assertEqual(msgs[0][1].field2[1].data, 22) self.assertEqual(msgs[0][1].field2[2].data, 33) self.assertEqual(msgs[0][1].field2[3].data, 44)
def test_addsub(self): tmp_rule_files = [ 'migrated_explicit_rules.py', 'migrated_mixed_rules.py', 'migrated_addsub_rules.py' ] rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files] inbag = "%s/test/migrated_addsub_gen1.bag" % (self.pkg_dir, ) outbag = "%s/test/migrated_addsub_gen1.fixed.bag" % (self.pkg_dir, ) mm = rosbagmigration.MessageMigrator(rule_files, False) res = rosbagmigration.checkbag(mm, inbag) self.assertTrue(not False in [m[1] == [] for m in res], 'Bag not ready to be migrated') res = rosbagmigration.fixbag(mm, inbag, outbag) self.assertTrue(res, 'Bag not converted successfully') msgs = [msg for msg in rosrecord.logplayer(outbag)] self.assertTrue(len(msgs) > 0) self.assertEqual(msgs[0][1].field1.field1, 42) self.assertEqual(msgs[0][1].field2.field1, 42)