def base_version_test(self):
     hive_holder = HiveHolder({}, {})
     parents_resource = Resource(
         SimpleCell(a1.block_name + BIICODE_FILE),
         Content(id_=None, load=Blob('[parent]\n ' + str(a1))))
     hive_holder.add_holder(BlockHolder(a1.block_name, {parents_resource}))
     parents_resource = Resource(
         SimpleCell(b2.block_name + BIICODE_FILE),
         Content(id_=None, load=Blob('[parent]\n * ' + str(b2))))
     hive_holder.add_holder(BlockHolder(b2.block_name, {parents_resource}))
     hive_holder.add_holder(BlockHolder(cn.block_name, {}))
     result_table = BlockVersionTable(
         [b.parent for b in hive_holder.block_holders])
     self.assertEqual(result_table, BlockVersionTable([a1, b2, cn]))
Exemple #2
0
    def test_delete_main(self):
        r1 = SimpleCell('user/block/r1.h', CPP)
        r2 = SimpleCell('user/block/r2.cpp', CPP)
        r3 = SimpleCell('user/block/r3.cpp', CPP)
        r4 = SimpleCell('user/block/' + BIICODE_FILE)

        res = {
            r1.name: Resource(r1, Content(None, Blob(''))),
            r2.name: Resource(r2, Content(None, Blob(''))),
            r3.name: Resource(r3, Content(None,
                                          Blob('int main(char* argv){}'))),
            r4.name: Resource(r4, Content(None, Blob('[mains]\n !r3.cpp')))
        }

        block_holder = BlockHolder(BlockName('user/block'), res)

        process_holder(block_holder, ParseProcessor())
        self.assertTrue(res['user/block/r3.cpp'].cell.hasMain)

        changes, _ = process_holder(block_holder, MainConfigProcessor())
        # Checks
        self.assertFalse(res['user/block/r1.h'].cell.hasMain)
        self.assertFalse(res['user/block/r2.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/r3.cpp'].cell.hasMain)
        self.assertEqual(0, len(changes.upserted))
Exemple #3
0
 def test_find_mains(self):
     '''basic check that header is implemented by source'''
     resources = {
         'blink.h':
         Resource(
             SimpleCell('usr/block/blink.h', CPP),
             Content(id_=None, load=Blob(header), parser=DRLCPPParser())),
         'blink.cpp':
         Resource(
             SimpleCell('usr/block/blink.cpp', CPP),
             Content(id_=None,
                     load=Blob(implementation),
                     parser=DRLCPPParser())),
         'mainblink.cpp':
         Resource(SimpleCell('usr/block/mainblink.cpp', CPP),
                  Content(id_=None, load=Blob(main), parser=DRLCPPParser()))
     }
     block_holder = BlockHolder(BlockName('user/block'), resources)
     for r in resources.itervalues():
         r.content.parse()
         r.content.updated = False
     processor = ArduinoEntryPointProcesor()
     processor.do_process(block_holder, Mock())
     mainblink = block_holder['mainblink.cpp'].cell
     content = block_holder['mainblink.cpp'].content
     self.assertTrue(mainblink.hasMain)
     self.assertFalse(content.updated)
     self.assertFalse(content.blob_updated)
Exemple #4
0
def checkin_files(hive_holder, settings, files, biiout):
    '''
    Params:
        hive_holder: HiveHolder
        files: dict{BlockCellName: Item (str or bytes loaded from file)}
        biiout: biiout
    Returns: ProcessorChanges
    '''
    logger.debug("----------- checkin  ---------------")
    hive = hive_holder.hive
    hive.settings = settings

    processor_changes = ProcessorChanges()
    if files is None:
        return processor_changes

    block_files = {}
    for block_cell_name, filecontent in files.iteritems():
        block_files.setdefault(block_cell_name.block_name,
                               {})[block_cell_name.cell_name] = filecontent

    for block_name, files in block_files.iteritems():
        checkin_block_files(hive_holder, block_name, files, processor_changes, biiout)

    for block_holder in hive_holder.block_holders:
        if block_holder.block_name not in block_files:
            processor_changes.deleted.update(block_holder.block_cell_names)
            hive_holder.add_holder(BlockHolder(block_holder.block_name, []))

    hive_holder.delete_empty_blocks()
    hive.update(processor_changes)

    # Raises if max is overtaken
    changevalidator.check_hive_num_cells(hive)
    return processor_changes
 def _cells_setup(self, block_name, cells_names, biitype):
     resources = []
     block_name = BlockName(block_name)
     for x in cells_names:
         cell = SimpleCell(block_name + x, BiiType(biitype))
         resources.append(Resource(cell, Mock()))
     return BlockHolder(block_name, resources)
Exemple #6
0
def checkin_files(hive_holder, settings, files, biiout):
    '''
    Params:
        hive_holder: HiveHolder
        files: dict{BlockCellName: Item (str or bytes loaded from file)}
        biiout: biiout
    Returns: ProcessorChanges
    '''
    logger.debug("----------- checkin  ---------------")
    hive_holder.settings = settings

    if files is None:
        return

    block_files = {}
    for block_cell_name, filecontent in files.iteritems():
        block_files.setdefault(block_cell_name.block_name,
                               {})[block_cell_name.cell_name] = filecontent

    for block_name, files in block_files.iteritems():
        checkin_block_files(hive_holder, block_name, files, biiout)

    for block_holder in hive_holder.block_holders:
        if block_holder.block_name not in block_files:
            hive_holder.add_holder(BlockHolder(block_holder.block_name, []))

    hive_holder.delete_empty_blocks()
def get_block_holder(block_name, resources_defs):
    resources = {}
    for cell_name, (typ, text) in resources_defs.iteritems():
        if typ is None:
            typ = UNKNOWN
        cell = SimpleCell(block_name + cell_name, typ)
        resources[cell_name] = Resource(
            cell, Content(block_name + cell_name, load=Blob(text)))
    return BlockHolder(block_name, resources)
Exemple #8
0
    def test_mains_with_filter(self):
        r1 = SimpleCell('user/block/r1.h', CPP)
        r2 = SimpleCell('user/block/r2.cpp', CPP)
        r3 = SimpleCell('user/block/no_mains/r3.cpp', CPP)
        r4 = SimpleCell('user/block/no_mains/r4.cpp', CPP)
        r5 = SimpleCell('user/block/' + BIICODE_FILE)
        r6 = SimpleCell('user/block/new_mains/r6.cpp', CPP)
        r7 = SimpleCell('user/block/new_mains/r7.cpp', CPP)
        r8 = SimpleCell('user/block/exe_file1.hh', CPP)
        r9 = SimpleCell('user/block/exe_file2.hh', CPP)

        res = {
            r1.name:
            Resource(r1, Content(None, Blob(''))),
            r2.name:
            Resource(r2, Content(None, Blob(''))),
            r3.name:
            Resource(r3, Content(None, Blob('int main(char* argv){}'))),
            r4.name:
            Resource(r4, Content(None, Blob('int main(char* argv){}'))),
            r5.name:
            Resource(
                r5,
                Content(None,
                        Blob('[mains]\n!no_mains/*\nnew_mains/*\n*.hh'))),
            r6.name:
            Resource(r6, Content(None, Blob(''))),
            r7.name:
            Resource(r7, Content(None, Blob(''))),
            r8.name:
            Resource(r8, Content(None, Blob(''))),
            r9.name:
            Resource(r9, Content(None, Blob('')))
        }

        block_holder = BlockHolder(BlockName('user/block'), res)

        process_holder(block_holder, ParseProcessor())
        self.assertTrue(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file2.hh'].cell.hasMain)

        process_holder(block_holder, MainConfigProcessor())

        # Checks
        self.assertFalse(res['user/block/r1.h'].cell.hasMain)
        self.assertFalse(res['user/block/r2.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file2.hh'].cell.hasMain)
Exemple #9
0
 def get_block_holder(self, block_version):
     """"
     return: BlockHolder
     """
     assert block_version.time is not None
     refs = References()
     block_cells_name = self.get_cells_snapshot(block_version)
     refs[block_version] = set(block_cells_name)
     resources = self.get_published_resources(refs)
     return BlockHolder(block_version.block_name, resources[block_version])
Exemple #10
0
 def __init__(self, hive, dict_cells, dict_contents):
     self.hive = hive
     resource_dict = defaultdict(list)
     for block_cell_name, cell in dict_cells.iteritems():
         content = dict_contents.get(block_cell_name)
         resource_dict[block_cell_name.block_name].append(
             Resource(cell, content))
     self._block_holders = {
         block_name: BlockHolder(block_name, resources)
         for block_name, resources in resource_dict.iteritems()
     }
Exemple #11
0
    def test_create_missing_simple_resources(self):
        resources = {'bii/virtual.bii': Resource(SimpleCell('user/block/bii/virtual.bii'),
                                                  Content(None, Blob(myConf1)))}
        self.block_holder = BlockHolder(BlockName('user/block'), resources)

        VirtualConfigurationProcessor().do_process(self.block_holder, OutputStream())

        self._sphere_os_checks('sphere.h')
        self._sphere_os_checks('sphere.cpp')

        self.assertEqual(None, self.block_holder['sphere.h'].content)
        self.assertEqual(None, self.block_holder['sphere.cpp'].content)
Exemple #12
0
 def __init__(self, dict_cells, dict_contents):
     self.hive_dependencies = None  # MUST BE ALWAYS BE ASSIGNED before usage
     self.settings = None
     resource_dict = defaultdict(list)
     for block_cell_name, cell in dict_cells.iteritems():
         content = dict_contents.get(block_cell_name)
         resource_dict[block_cell_name.block_name].append(
             Resource(cell, content))
     self._block_holders = {
         block_name: BlockHolder(block_name, resources)
         for block_name, resources in resource_dict.iteritems()
     }
Exemple #13
0
    def prepare_context(self, config):
        r1 = SimpleCell('user/block/r1.h')
        r2 = SimpleCell('user/block/r2.cpp')
        r3 = SimpleCell('user/block2/r3.cpp')
        r4 = SimpleCell('user/block/' + BIICODE_FILE)

        self.res = {r1.name: Resource(r1, None),
                    r2.name: Resource(r2, None),
                    r3.name: Resource(r3, None),
                    r4.name: Resource(r4, Content(None, Blob("[mains]\n" + config)))}

        self.block_holder = BlockHolder(BlockName('user/block'), self.res)
        self.processor = MainConfigProcessor()
Exemple #14
0
def get_block_holder(block_cell_names, biitype=BiiType(UNKNOWN)):
    '''Given a working set, a list of resources and a biitype constant
     - Adds every resource to the working set and assign given type
     - Read test files from disk as binary or systext depending on given type and creates contents
     - Fills a wsHolder with given resources and created contents
    '''

    resources = []
    for name in block_cell_names:
        cell = SimpleCell(name, biitype)
        content = make_content(name, biitype)
        resources.append(Resource(cell, content))

    block_name = BlockCellName(iter(block_cell_names).next()).block_name
    return BlockHolder(block_name, resources)
Exemple #15
0
    def _process_from_contents(self, contents):
        '''param contents: dict{name:code snippets}.
        Will create a HiveHolder, fill with the data and process it'''
        resources = []
        for name, content in contents.iteritems():
            cell = SimpleCell(name, CPP)
            block_name = cell.name.block_name
            resources.append(
                Resource(
                    cell,
                    Content(name, load=Blob(content), parser=DRLCPPParser())))

        block_holder = BlockHolder(block_name, resources)
        self._process(block_holder)
        return block_holder
Exemple #16
0
    def _prepare_context(self, my_conf):
        if my_conf:
            my_conf = "[dependencies]\n " + my_conf
        self.processor = DependenciesConfigurationProcessor()
        self.r1 = BlockCellName('user/block/r1.h')
        self.r2 = BlockCellName('user/block/r2.cpp')
        self.r3 = BlockCellName('user/block/r3.cpp')
        r1 = SimpleCell(self.r1, CPP)
        r2 = SimpleCell(self.r2, CPP)
        r3 = SimpleCell('user/block/r3.cpp', CPP)

        r4 = SimpleCell('user/block/' + BIICODE_FILE)
        res = {
            r1.name: Resource(r1, Content(None, Blob("hi"))),
            r2.name: Resource(r2, Content(None, Blob("hi"))),
            r3.name: Resource(r3, Content(None, Blob("hi"))),
            r4.name: Resource(r4, Content(None, Blob(my_conf)))
        }
        return BlockHolder(BlockName('user/block'), res)
Exemple #17
0
def checkin_block_files(hive_holder, block_name, files, processor_changes, biiout):
    '''
    Params:
        hive_holder: HiveHolder
        block_name: BlockName
        files: {cell_name: content}
        processor_changes: ProcessorChanges
        biiout: biiout
    '''
    block_name = BlockName(block_name)
    types_blobs = obtain_types_blobs(files)  # {cell_name: (TYPE, Content/CellType/None)}
    # FIXME: What happens if merge result is larger than individual files, reject???
    changevalidator.remove_large_cells(types_blobs, biiout)
    try:
        block_holder = hive_holder[block_name]
    except KeyError:
        block_holder = BlockHolder(block_name, [])
        hive_holder.add_holder(block_holder)

    for cell_name, (biitype, blob) in types_blobs.iteritems():
        block_cell_name = block_name + cell_name
        cell = SimpleCell(block_cell_name, biitype)
        try:
            resource = block_holder[cell_name]
        except KeyError:
            content = Content(block_cell_name, load=blob)
            processor_changes.upsert(block_cell_name, content)
        else:
            content = resource.content
            if content is None or blob != content.load:
                content = Content(block_cell_name, load=blob)
                processor_changes.upsert(block_cell_name, content)

        resource = Resource(cell, content)
        block_holder.add_resource(resource)

    for cell_name, resource in block_holder.resources.items():
        if cell_name not in types_blobs:
            if resource.content is not None:
                processor_changes.delete(resource.name)
            block_holder.delete_resource(cell_name)
    hive_holder.hive.update(processor_changes)