def test_different_rename_same_new(self, action, use_other): base_resources = self.common.copy() other_resources = base_resources.copy() result = base_resources.copy() base_resources.pop("file1.h") base_resources["file45.h"] = "Content of file1.h\n" other_resources.pop("file2.h") other_resources["file45.h"] = "Content of file2.h\n" result.pop("file1.h") result.pop("file2.h") base_renames = Renames() base_renames[CellName("file1.h")] = CellName("file45.h") other_renames = Renames() other_renames[CellName("file2.h")] = CellName("file45.h") if action == 'modify': base_resources['file45.h'] = 'Updated file 45\n' result["file45.h"] = 'Updated file 45\n' elif action == 'double_modify': msg = 'Updated file45.h\n' base_resources['file45.h'] = msg other_resources['file45.h'] = msg result["file45.h"] = msg if use_other: base_resources, other_resources = other_resources, base_resources base_renames, other_renames = other_renames, base_renames ret = self.merger.merge(base_resources, other_resources, self.common, base_renames, other_renames) self.assertEqual(result, ret) self.assertNotIn("CONFLICT", str(self._biiout))
def test_renames(self): publish_request = PublishRequest(BlockVersion(self.brl, -1)) publish_request.cells.append(SimpleCell('user/block/r1.h')) publish_request.contents['r1.h'] = Content(id_=None, load=None) publish_request.cells.append(SimpleCell('user/block/r2.h')) publish_request.contents['r2.h'] = Content(id_=None, load=None) publish_request.cells.append(SimpleCell('user/block/r3.h')) publish_request.contents['r3.h'] = Content(id_=None, load=None) publish_request.tag = STABLE self.block.add_publication(publish_request) publish_request = PublishRequest(BlockVersion(self.brl, 0)) publish_request.cells.append(SimpleCell('user/block/r11.h')) publish_request.deleted.append('r1.h') publish_request.renames = Renames( {CellName('r1.h'): CellName('r11.h')}) publish_request.tag = STABLE self.block.add_publication(publish_request) publish_request = PublishRequest(BlockVersion(self.brl, 1)) publish_request.cells.append(SimpleCell('user/block/r21.h')) publish_request.deleted.append('r2.h') publish_request.renames = Renames( {CellName('r2.h'): CellName('r21.h')}) publish_request.tag = STABLE self.block.add_publication(publish_request) self.assertEquals({}, self.block.get_renames(0, 0)) self.assertEquals({'r1.h': 'r11.h'}, self.block.get_renames(0, 1)) self.assertEquals({ 'r2.h': 'r21.h', 'r1.h': 'r11.h' }, self.block.get_renames(0, 2))
def test_same_rename(self, action, use_other): base_resources = self.common.copy() base_resources["file45.h"] = base_resources["file1.h"] base_resources.pop("file1.h", None) base_renames = Renames() base_renames[CellName("file1.h")] = CellName("file45.h") result = base_resources.copy() other_resources = base_resources.copy() other_renames = base_renames.copy() if action == 'modify': other_resources['file45.h'] = 'Updated file1.h\n' result["file45.h"] = 'Updated file1.h\n' elif action == 'double_modify': other_resources['file45.h'] = 'Updated file1.h\n' base_resources['file45.h'] = 'Updated file1.h\n' result["file45.h"] = 'Updated file1.h\n' if use_other: base_resources, other_resources = other_resources, base_resources base_renames, other_renames = other_renames, base_renames ret = self.merger.merge(base_resources, other_resources, self.common, base_renames, other_renames) self.assertEqual(result, ret) self.assertNotIn("CONFLICT", str(self._biiout))
def test_rename_conflict(self, action, use_other): base_resources = self.common.copy() other_resources = self.common.copy() result = base_resources.copy() base_resources["file45.h"] = 'Updated file1.h\n' base_resources.pop("file1.h", None) base_renames = Renames() base_renames[CellName("file1.h")] = CellName("file45.h") other_renames = Renames() if action == 'delete': other_resources.pop("file1.h") result.pop("file1.h", None) result["file45.h"] = 'Updated file1.h\n' elif action == 'modify': other_resources['file1.h'] = 'Updated file12.h\n' result.pop("file1.h", None) result["file45.h"] = '<<<<<<<<<<<<<<<<<<<<<<<<< base\n' \ 'Updated file12.h\n\n' \ '=========================\n' \ 'Updated file1.h\n\n' \ '>>>>>>>>>>>>>>>>>>>>>>>>> other\n' if use_other: base_resources, other_resources = other_resources, base_resources base_renames, other_renames = other_renames, base_renames ret = self.merger.merge(base_resources, other_resources, self.common, base_renames, other_renames) self.assertEqual(result, ret) self.assertIn("CONFLICT", str(self._biiout))
def test_serialize(self): r = Renames() r[CellName('a.h')] = CellName('b.h') r[CellName('b.h')] = CellName('c.h') s = serialize(r) d = Renames.deserialize(s) self.assertIsInstance(d, Renames) self.assertEqual(r, d)
def test_cat(self): r = Renames() r[CellName('a.h')] = CellName('b.h') r2 = Renames() r2[CellName('b.h')] = CellName('c.h') r2[CellName('d.h')] = CellName('e.h') r.cat(r2) self.assertEqual(r[CellName('a.h')], CellName('c.h')) self.assertEqual(r[CellName('d.h')], CellName('e.h')) self.assertEqual(2, len(r))
def get_renames(self, begin, end): '''Gets renames between given versions Paramenters: begin: int, excluded end: int, included Returns: Dict { old_cell_name => new_cell_name} ''' renames = Renames() for r in self._renames.xrange(begin + 1, end + 1): renames.cat(r) return renames
def _changes(): changes = Changes() changes.deleted['deleted'] = Resource(None, 'old_content') changes.deleted['renamed'] = Resource( SimpleCell('usr/block/renamed'), Content(ID((1234, )), load=Blob('old_content2'))) changes.created['created'] = Resource( SimpleCell('usr/block/created'), Content(id_=None, load=Blob('created'))) changes.created['renamed2'] = Resource( SimpleCell('usr/block/renamed2'), Content(id_=None, load=Blob('old_content2'))) changes.modified['modified_cont'] = Modification( Resource(SimpleCell('usr/block/modified_cont'), Content(id_=None, load=Blob('mod_content'))), Resource(SimpleCell('usr/block/modified_cont'), Content(id_=None, load=Blob('mod_content2')))) changes.modified['modified_cell'] = Modification( Resource(SimpleCell('usr/block/modified_cell'), Content(id_=None, load=Blob('mod_cell'))), Resource(SimpleCell('usr/block/modified_cell', CPP), Content(id_=None, load=Blob('mod_cell')))) changes.modified['modified_both'] = Modification( Resource(SimpleCell('usr/block/modified_both'), Content(id_=None, load='mod_both')), Resource(SimpleCell('usr/block/modified_both', CPP), Content(id_=None, load=Blob('mod_both2')))) changes.renames = Renames({'renamed': 'renamed2'}) return changes
def deserialize(data): '''From dictionary to object Publish Pack''' pp = PublishRequest() pp.parent = BlockVersion.deserialize( data[PublishRequest.SERIAL_TRACKED_KEY]) pp.parent_time = data[PublishRequest.SERIAL_PARENT_DATETIME] pp.tag = VersionTag.deserialize(data[PublishRequest.SERIAL_TAG_KEY]) pp.msg = data[PublishRequest.SERIAL_MSG_KEY] # Backward client compatibility pp.versiontag = data.get(PublishRequest.SERIAL_VTAG_KEY, None) pp.deptable = BlockVersionTable.deserialize( data[PublishRequest.SERIAL_DEP_TABLE]) pp.cells = ListDeserializer(CellDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CELLS_KEY]) pp.deleted = ListDeserializer(CellName).\ deserialize(data[PublishRequest.SERIAL_DELETED_KEY]) pp.renames = Renames.deserialize( data[PublishRequest.SERIAL_RENAMES_KEY]) pp.contents = DictDeserializer(CellName, ContentDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_KEY]) pp.contents_ids = DictDeserializer(CellName, ID).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_ID_KEY]) # Backward client compatibility pp.origin = OriginInfo.deserialize( data.get(PublishRequest.SERIAL_ORIGIN_INFO, None)) return pp
def get_renames(self, brl_block, t1, t2): ret = Renames() if t2 == 6: ret[CellName("r1.h")] = CellName("r3.h") elif t2 == 7: ret[CellName("r3.h")] = CellName("r4.h") return ret
def __init__(self): self.deleted = {} """dict of deleted {ID: Object} where object can be the diff, None if not necessary""" self.created = {} """dict {ID: Object} Where Value can be either a Cell, a Content or a Resource""" self.modified = {} """dict {ID: Modification} ID is the OldID in case of Rename.""" self.renames = Renames() """dict {oldID: newID}""" self.sim_limit = 0.75
def test_different_rename_same_new_conflict(self, action, use_other): base_resources = self.common.copy() other_resources = base_resources.copy() result = base_resources.copy() base_resources.pop("file1.h") base_resources["file45.h"] = "Content of file1.h\n" other_resources.pop("file2.h") other_resources["file45.h"] = "Content of file2.h\n" result.pop("file1.h") result.pop("file2.h") base_renames = Renames() base_renames[CellName("file1.h")] = CellName("file45.h") other_renames = Renames() other_renames[CellName("file2.h")] = CellName("file45.h") n1, n2 = (1, 2) if not use_other else (2, 1) if action == 'modify': base_resources['file45.h'] = 'File45.h updated 1\n' other_resources['file45.h'] = 'File45.h updated 2\n' result["file45.h"] = '<<<<<<<<<<<<<<<<<<<<<<<<< base\n' \ 'File45.h updated %d\n\n'\ '=========================\n'\ 'File45.h updated %d\n\n'\ '>>>>>>>>>>>>>>>>>>>>>>>>> other\n' % (n1, n2) else: result['file45.h'] = '<<<<<<<<<<<<<<<<<<<<<<<<< base\n' \ 'Content of file%d.h\n\n'\ '=========================\n'\ 'Content of file%d.h\n\n'\ '>>>>>>>>>>>>>>>>>>>>>>>>> other\n' % (n1, n2) if use_other: base_resources, other_resources = other_resources, base_resources base_renames, other_renames = other_renames, base_renames ret = self.merger.merge(base_resources, other_resources, self.common, base_renames, other_renames) self.assertIn("CONFLICT", str(self._biiout)) self.assertEqual(result, ret)
def deduce_renames(self): renames = Renames() for created_key, created_value in self.created.iteritems(): if hasattr(created_value, 'similarity'): max_sim, max_key = 0.0, None for deleted_key, deleted_value in self.deleted.iteritems(): sim = created_value.similarity(deleted_value) if sim > max_sim: max_sim, max_key = sim, deleted_key if max_sim > self.sim_limit: renames[max_key] = created_key self.renames = renames
def __init__(self, parent=None): self.parent = parent # BlockVersion, the one to compute the changes self.parent_time = None # DateTime of the parent publication, obtained from Delta #self._changes = None # Transient Changes object self.msg = "" self.tag = DEV self.versiontag = None self.deptable = None # Internal status, deducible from changes self.cells = [] # [] of cells self.deleted = [] # [] of cell_names self.contents = {} # {CellName: Content} self.contents_ids = {} # {CellName: ContentID} self.renames = Renames() self.origin = None
def deserialize(data): '''From dictionary to object Publish Pack''' pp = PublishRequest() pp.parent = BlockVersion.deserialize(data[PublishRequest.SERIAL_TRACKED_KEY]) pp.parent_time = data[PublishRequest.SERIAL_PARENT_DATETIME] pp.tag = VersionTag.deserialize(data[PublishRequest.SERIAL_TAG_KEY]) pp.msg = data[PublishRequest.SERIAL_MSG_KEY] # Backward client compatibility pp.versiontag = data.get(PublishRequest.SERIAL_VTAG_KEY, None) pp.deptable = BlockVersionTable.deserialize(data[PublishRequest.SERIAL_DEP_TABLE]) pp.cells = ListDeserializer(CellDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CELLS_KEY]) pp.deleted = ListDeserializer(CellName).\ deserialize(data[PublishRequest.SERIAL_DELETED_KEY]) pp.renames = Renames.deserialize(data[PublishRequest.SERIAL_RENAMES_KEY]) pp.contents = DictDeserializer(CellName, ContentDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_KEY]) pp.contents_ids = DictDeserializer(CellName, ID).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_ID_KEY]) # Backward client compatibility pp.origin = OriginInfo.deserialize(data.get(PublishRequest.SERIAL_ORIGIN_INFO, None)) return pp
def test_renames(self): r = Renames({"old.h": "new.h", "old2.h": "old3.h"}) s = serialize(r) #print "S RENAMES: " + str(s) r2 = Renames.deserialize(s) self.assertEqual(r, r2)
def test_double_rename(self): r = Renames() r[CellName('a.h')] = CellName('b.h') r[CellName('b.h')] = CellName('c.h') self.assertEqual(r[CellName('a.h')], CellName('b.h')) self.assertEqual(r[CellName('b.h')], CellName('c.h'))
def test_get_old_name(self): r = Renames() r[CellName('a.h')] = CellName('b.h') r[CellName('b.h')] = CellName('c.h') self.assertEqual('a.h', r.get_old_name('b.h'))
def test_basic(self): r = Renames() r[CellName('a.h')] = CellName('a.h') self.assertEqual(0, len(r))