Пример #1
0
    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))
Пример #2
0
    def setUp(self):
        self.folder = self.new_tmp_folder()

        brl_block = BRLBlock('dummy/dummy/block/master')
        self.block_version = BlockVersion(brl_block, 0)

        alf = Resource(SimpleCell("dummy/block/alf.c"),
                       Content(ID((0, 1, 2)), Blob("Hello Alf")))
        alf.cell.ID = ID((0, 1, 2))
        willy = Resource(SimpleCell("dummy/block/willy.c"),
                         Content(ID((0, 1, 3)), Blob("Hello Willy")))
        willy.cell.ID = ID((0, 1, 45))

        self.referenced_resources = ReferencedResources()
        self.referenced_resources[self.block_version].update({
            CellName("alf.c"):
            alf,
            CellName("willy.c"):
            willy
        })
        self.cells_snapshot = [CellName("alf.c"), CellName("willy.c")]
        self.dep_table = BlockVersionTable()

        self.restapi = Mock(BiiAPI)
        self.restapi.get_published_resources.return_value = self.referenced_resources
        self.restapi.get_cells_snapshot.return_value = self.cells_snapshot
        self.restapi.get_dep_table.return_value = self.dep_table
        self.restapi.get_version_delta_info.return_value = BlockDelta(
            '', DEV, None)
        self.localdb = LocalDB(os.path.join(self.folder, 'bii.db'))
        self.proxy = BiiAPIProxy(self.localdb, self.restapi, Mock())
Пример #3
0
    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))
Пример #4
0
 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))
Пример #5
0
    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))
Пример #6
0
 def test_store_snapshot(self):
     original_snap = [CellName("alf.c"), CellName("willy.c")]
     brl_block = BRLBlock('dummy/dummy/block/master')
     block_version = BlockVersion(brl_block, 0)
     self.db.create_cells_snapshot(block_version, original_snap)
     retrieved_snap = self.db.get_cells_snapshot(block_version)
     self.assertEquals(original_snap, retrieved_snap)
Пример #7
0
    def test_deduce_renames_multi_all_equal(self):
        '''2 is deleted
           3 is created with 2's contents
           4 is created with 2's contents
           2 is considered to be renamed to 4
        '''
        #FIXME: Conclusion is arbitrary. Last one to be processed with equal similarty degreee
        # is the one choosen. We might have to inform the user about this
        base_resources = {CellName('1'): Int(1), CellName('2'): Int(2)}
        other_resources = {
            CellName('1'): Int(1),
            CellName('3'): Int(2),
            CellName('4'): Int(2)
        }

        #compute changes without renames
        changes = compare(base_resources, other_resources)
        changes.deduce_renames()
        #nothing changes
        self.assertEqual({CellName('2'): 2}, changes.deleted)
        self.assertEqual({
            CellName('3'): Int(2),
            CellName('4'): 2
        }, changes.created)
        self.assertEqual({}, changes.modified)
        self.assertEqual({CellName('2'): CellName('4')}, changes.renames)
Пример #8
0
    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
Пример #9
0
 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)
Пример #10
0
 def test_references(self):
     r = References()
     bv3 = BlockVersion(BRLBlock('user/user/block/master'), 3)
     bv4 = BlockVersion(BRLBlock('user/user/block/master'), 4)
     cn0 = CellName('foo.h')
     cn1 = CellName('foo1.h')
     r[bv3].add(cn0)
     r[bv3].add(cn1)
     r[bv4].add(cn0)
     l = r.explode()
     self.assertEqual({(bv3, cn0), (bv3, cn1), (bv4, cn0)}, set(l))
Пример #11
0
    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))
Пример #12
0
    def test_cached_references(self):
        s = References()
        s[self.block_version] = {CellName("alf.c"), CellName("willy.c")}

        self.proxy.get_published_resources(s)

        self.assertTrue(self.restapi.get_published_resources.called)
        self.restapi.get_published_resources.called = False

        c = self.proxy.get_published_resources(s)
        self.assertFalse(self.restapi.get_published_resources.called)
        self.assertEqual(c, self.referenced_resources)
Пример #13
0
 def test_reference(self):
     #With a simple CellName inside
     rf = Reference(BlockVersion('user/user/block/master', 1),
                    CellName('f1.h'))
     s = rf.serialize()
     rf2 = Reference.deserialize(s)
     self.assertEqual(rf, rf2)
Пример #14
0
 def test_address_table(self):
     a = AddressTable(ID((1, 3)))
     a.create(CellName('f2.h'), ID((1, 3, 18)), 2)
     s = serialize(a)
     #print "S: " + str(s)
     b = AddressTable.deserialize(s, ID((1, 3)))
     #print "B: " + str(b)
     self.assertEqual(a, b)
Пример #15
0
    def test_store_published_resources(self):
        s = References()
        brl_block = BRLBlock('dummy/dummy/block/master')
        block_version = BlockVersion(brl_block, 0)
        s[block_version] = [
            CellName("alf.c"),
            CellName("willy.c"),
            CellName('maya.h'),
            CellName('win/maya.h'),
            CellName('nix/maya.h')
        ]

        alf = Resource(SimpleCell("dummy/block/alf.c"),
                       Content(ID((0, 1, 2)), Blob("Hello Alf")))
        alf.cell.ID = ID((0, 1, 2))
        willy = Resource(SimpleCell("dummy/block/willy.c"),
                         Content(ID((0, 1, 3)), Blob("Hello Willy")))
        willy.cell.ID = ID((0, 1, 45))
        maya_v = Resource(VirtualCell("dummy/block/maya.h"), None)
        maya_v.cell.ID = ID((0, 1, 3))
        maya_win = Resource(SimpleCell("dummy/block/win/maya.h"),
                            Content(ID((0, 1, 4)), Blob("Hello Maya")))
        maya_win.cell.ID = ID((0, 1, 4))
        maya_nix = Resource(SimpleCell("dummy/block/nix/maya.h"),
                            Content(ID((0, 1, 5)), Blob("Hello Maya")))
        maya_nix.cell.ID = ID((0, 1, 5))

        # Expected return
        referenced_resources = ReferencedResources()
        referenced_resources[block_version].update({
            CellName("alf.c"):
            alf,
            CellName("willy.c"):
            willy,
            CellName('maya.h'):
            maya_v,
            CellName('win/maya.h'):
            maya_win,
            CellName('nix/maya.h'):
            maya_nix,
        })

        self.db.create_published_resources(referenced_resources)
        retrieved = self.db.get_published_resources(s)

        self.assertEquals(referenced_resources, retrieved)
Пример #16
0
    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)
Пример #17
0
def migrate_block_files(block_name, block_files, biiout):
    """ actual migration, takes params
    param block_name: BlockName
    param block_files: {CellName: Blob load}
    param biiout: standar bii output
    """
    old_names = ['requirements', 'parents', 'paths', 'dependencies', 'mains']
    old_names = OrderedDict([(k, k) for k in old_names])
    old_names['parents'] = 'parent'

    old_files = [
        name for name in old_names if 'bii/%s.bii' % name in block_files
    ]
    if not old_files:
        return

    deleted = []

    if BIICODE_FILE in block_files:
        biiout.warn(
            "The following old configuration files exist in your %s block\n"
            "%s\nMigrating them to your existing %s file, please check it" %
            (block_name, ', '.join(old_files), BIICODE_FILE))

    current_config = [
        "# Biicode configuration file migrated from old config files\n"
    ]
    for file_name, config_name in old_names.iteritems():
        current_config.append("[%s]" % config_name)
        if file_name in old_files:
            config_file = 'bii/%s.bii' % file_name
            biiout.warn("Migrating old %s file to new %s configuration file" %
                        (config_file, BIICODE_FILE))
            content = block_files.pop(config_file)
            deleted.append(config_file)
            for line in content.splitlines():
                current_config.append("\t%s" % line)
        current_config.append("")

    current_config.append('[hooks]\n\n[includes]\n\n[data]')
    # This migrate the old data defined in the bii:// way
    for name, content in block_files.iteritems():
        biitype = BiiType.from_extension(CellName(name).extension)
        if biitype == CPP:
            _, data, _, _, _ = FileParser().parse(content)
            if data:
                data_str = ' '.join(d.name for d in data)
                current_config.append('\t%s + %s' % (name, data_str))

    config_text = '\n'.join(current_config)
    return config_text, deleted
Пример #18
0
 def test_accept(self):
     ig = BiiIgnore.defaults()
     self.assertFalse(ig.ignored('path/file.patata'))
     self.assertFalse(ig.ignored(CellName('path/to/file.h')))
     self.assertFalse(ig.ignored(CellName('path/to.to/file.h')))
     self.assertFalse(ig.ignored(CellName('file.cpp')))
     self.assertFalse(ig.ignored(CellName('file.inl')))
     self.assertFalse(ig.ignored(CellName('file.ipp')))
     self.assertFalse(ig.ignored(CellName('Dense')))
Пример #19
0
    def test_deduce_renames_multi_different_values(self):
        '''2 is deleted
           3 is created with 3
           4 is created with 4
           2 is considered to be renamed to 3
        '''
        base_resources = {CellName('1'): Int(1), CellName('2'): Int(2)}
        other_resources = {
            CellName('1'): Int(1),
            CellName('3'): Int(3),
            CellName('4'): Int(4)
        }

        #compute changes without renames
        changes = compare(base_resources, other_resources)
        changes.deduce_renames()
        #nothing changes
        self.assertEqual({CellName('2'): 2}, changes.deleted)
        self.assertEqual({
            CellName('3'): Int(3),
            CellName('4'): 4
        }, changes.created)
        self.assertEqual({}, changes.modified)
        self.assertEqual({CellName('2'): CellName('3')}, changes.renames)
Пример #20
0
    def test_add(self):
        mName = BlockName("user2/module2")
        m = mName + "path/to/file2.h"
        self.assertEqual('user2/module2/path/to/file2.h', m)
        self.assertEqual('user2/module2', m.block_name)
        self.assertEqual('user2', m.block_name.user)
        self.assertEqual('path/to/file2.h', m.cell_name)
        self.assertEqual('.h', m.extension)

        m = mName + CellName("path/to/file2.h")
        self.assertEqual('user2/module2/path/to/file2.h', m)
        self.assertEqual('user2/module2', m.block_name)
        self.assertEqual('user2', m.block_name.user)
        self.assertEqual('path/to/file2.h', m.cell_name)
        self.assertEqual('.h', m.extension)
Пример #21
0
    def test_fiunder_request_existing(self):
        f = FinderRequest()
        self.assertFalse(f)
        existing = ReferencedDependencies()
        version = BlockVersion('user/user/block/master', 1)
        existing[version][CPPDeclaration("file.h")].add(CellName("file.h"))
        f.existing = existing
        f.update = True
        f.policy = Policy.default()
        #print f
        s = f.serialize()
        #print s
        f2 = FinderRequest.deserialize(s)

        self.assertEquals(f, f2)
        self.assertTrue(f2)
Пример #22
0
 def __new__(cls, value, validate=True):
     if not validate:
         obj = str.__new__(cls, value)
     else:
         try:
             value = value.strip().replace('\\', '/')
             tokens = value.split('/', 2)
             cell = CellName(tokens[2])
             block = BlockName('/'.join(tokens[:2]))
             obj = str.__new__(cls, '%s/%s' % (block, cell))
             obj._block = block
             obj._cell = cell
         except IndexError:
             error_message = 'Invalid BlockCellName %s. '\
                             'It should be in the form usr/block/cellname' % value
             raise InvalidNameException(error_message)
     return obj
Пример #23
0
 def visit_FunctionDef(self, node):
     doc_string = None
     try:
         (name, lastLine, leaves) = parse_validate_virtual_func(node)
         code_lines = code.splitlines()[node.lineno - 1:lastLine]
         code_lines[0] = code_lines[0].replace(name, 'virtual')
         virtual_logic = '\n'.join(code_lines)
         doc_string = ast.get_docstring(node)
         filenames = files_sep_pattern.findall(doc_string)
         cells_to_apply = {CellName(item) for item in filenames}
         r = VirtualParseResult(virtual_logic, leaves, cells_to_apply)
         self.result[name] = r
     except BiiException as e:
         raise e
     except Exception as e:
         if doc_string is None:
             raise VirtualParserException(
                 'Missing docstring in virtual config definition')
         raise VirtualParserException(
             'There was an error while parsing virtual.bii file '
             '%s' % str(e))
Пример #24
0
    def test_changes(self):
        c = Changes()
        c.add_created(CellName("resource1"), "resource1")
        c.add_created(CellName("resource2"), "resource2")
        c.add_deleted(CellName("resource3"), "resource3")

        c.add_modified(CellName("resource4"),
                       Modification("resource3", "resource4"))
        c.add_rename(CellName("resource5"), CellName("resource6"))
        c.sim_limit = 23

        s = c.serialize()
        deserializer = ChangesDeserializer(CellName, str)
        c2 = deserializer.deserialize(s)
        self.assertEqual(c.created, c2.created)
        self.assertEqual(c.deleted, c2.deleted)
        self.assertEqual(c.modified, c2.modified)
        self.assertEqual(c.renames, c2.renames)
Пример #25
0
 def deserialize(data):
     return Reference(BlockVersion.deserialize(data[0]),
                      CellName.deserialize(data[1]))
Пример #26
0
 def test_addition(self):
     sut = BlockVersion("testU/testU/math/block", 0)
     cell_name = CellName("path/to/file.h")
     ref = sut + cell_name
     self.assertEquals(ref, Reference(sut, cell_name))
Пример #27
0
 def _parse(self):
     # Data must be already validated
     tokens = self.split('/', 2)
     self._block = BlockName('/'.join(tokens[:2]), False)
     self._cell = CellName(tokens[2], False)
Пример #28
0
 def deserialize(data):
     return Reference(BlockVersion.deserialize(data[0]), CellName.deserialize(data[1]))
Пример #29
0
 def test_name(self):
     m = BRLBlock('owner/user/block/branch')
     mv = BlockVersion(m, 3)
     r = Reference(mv, CellName('path/to/file.h'))
     self.assertEqual('user/block/path/to/file.h', r.block_cell_name())
Пример #30
0
 def test_deepcopy(self):
     r = References()
     r[BlockVersion(BRLBlock('user/user/block/branch'),
                    3)].add(CellName('f1.h'))
     r2 = copy.deepcopy(r)
     self.assertEqual(r, r2)
Пример #31
0
    def test_deduce_renames(self):
        ''' 2 is modified from 2 to 22
            3 is deleted
            5 is renamed to 6 (5 deleted, 6 created)
            10 is created'''
        base_resources = {
            CellName('1'): Int(1),
            CellName('2'): Int(2),
            CellName('3'): Int(3),
            CellName('4'): Int(4),
            CellName('5'): Int(5)
        }
        other_resources = {
            CellName('1'): Int(1),
            CellName('2'): Int(22),
            CellName('4'): Int(4),
            CellName('6'): Int(6),
            CellName('10'): Int(10)
        }

        #compute changes without renames
        changes = compare(base_resources, other_resources)
        self.assertEqual({CellName('3'): 3, CellName('5'): 5}, changes.deleted)
        self.assertEqual({
            CellName('6'): Int(6),
            CellName('10'): 10
        }, changes.created)
        self.assertEqual({CellName('2'): (2, 22)}, changes.modified)
        self.assertEqual({}, changes.renames)

        #deduce renames
        changes.deduce_renames()
        #nothing changes
        self.assertEqual({CellName('3'): 3, CellName('5'): 5}, changes.deleted)
        self.assertEqual({
            CellName('6'): Int(6),
            CellName('10'): 10
        }, changes.created)
        self.assertEqual({CellName('2'): (2, 22)}, changes.modified)
        #but the renames field
        self.assertEqual({CellName('5'): CellName('6')}, changes.renames)
 def test_cell_name(self):
     b = CellName("path/to/f1.h")
     s = b.serialize()
     b2 = CellName.deserialize(s)
     self.assertEqual(b, b2)