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() processor = ArduinoEntryPointProcesor() changes = ProcessorChanges() processor.do_process(block_holder, changes, Mock()) self.assert_bii_equal(changes, ProcessorChanges()) mainblink = block_holder['mainblink.cpp'].cell self.assertTrue(mainblink.hasMain)
def commit_conf(block_holder): new_resource = block_holder.commit_config() if new_resource: processor_changes = ProcessorChanges() processor_changes.upsert(new_resource.name, new_resource.content, blob_changed=True) hive.update(processor_changes) editionapi.save_hive_changes(hive, processor_changes)
def test_hive_num_files_reject(self): with self.assertRaises(BiiException): hive = Hive() changes = ProcessorChanges() for i in xrange(BII_HIVE_NUMFILES_LIMIT + 1): name = "user/block/file%d" % i changes.upsert(name, Content(id_=name, load=Blob())) hive.update(changes) changevalidator.check_hive_num_cells(hive)
def make_simple_cell(block_cell_name, hive=None): if isinstance(block_cell_name, basestring): block_cell_name = BlockCellName(block_cell_name) cell = SimpleCell(block_cell_name) cell.type = BiiType.from_extension(block_cell_name.extension) if hive: changes = ProcessorChanges() changes.upsert(cell.name, cell, None) hive.update(changes) return cell
def make_simple_cell(block_cell_name, hive=None): if isinstance(block_cell_name, basestring): block_cell_name = BlockCellName(block_cell_name) cell = SimpleCell(block_cell_name) cell.type = BiiType.from_extension(block_cell_name.extension) if hive: changes = ProcessorChanges() changes.upsert(cell.name, cell, None) hive.update(changes) return cell
def _process_resources(block_holder): processor_changes = ProcessorChanges() for (cell, content) in block_holder.simple_resources: # Cell from server has the CellID as ID, we need BlockCellName cell.ID = cell.name if content: # content.ID = cell.name hive.add_resource does it content._is_parsed = False # It is necessary to parse it content.ID = cell.name # It is edition, should have ID=BlockCellName r = Resource(cell, content) block_holder.add_resource(r) processor_changes.upsert(r.name, r.content, blob_changed=True) return processor_changes
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 simple_dependencies_cpp_test(self): block_holder = self._cells_setup( 'dummy/geom', ['sphere.h', 'sphere.cpp', 'main.cpp'], CPP) # Parse processor setup block_holder['main.cpp'].cell.dependencies.unresolved = { CPPDeclaration('iostream'), CPPDeclaration('sphere.h') } block_holder['sphere.cpp'].cell.dependencies.unresolved = { CPPDeclaration('math.h'), CPPDeclaration('iostream'), CPPDeclaration('sphere.h') } changes, _ = process_holder(block_holder, DependenciesProcessor()) # Checks self.assert_bii_equal(changes, ProcessorChanges()) mainR = block_holder['main.cpp'].cell self.check_dependency_set(mainR.dependencies, resolved=['sphere.h', 'iostream'], explicit=['dummy/geom/sphere.h'], system=['iostream']) sphereR = block_holder['sphere.cpp'].cell self.check_dependency_set(sphereR.dependencies, resolved=['sphere.h', 'iostream', 'math.h'], explicit=['dummy/geom/sphere.h'], system=['iostream', 'math.h'])
def apply_find_result(self, find_result): from biicode.common.find import find_manager if find_result: hive_holder = self.hive_holder processor_changes = ProcessorChanges() find_manager.update_hive_with_find_result(hive_holder, find_result, processor_changes) blocks_process(hive_holder, processor_changes, self._biiout) deps_process(self._biiapi, hive_holder, processor_changes, self._biiout) self._edition.save_hive_changes(hive_holder.hive, processor_changes)
def process_holder(holder, processor): """This function performs common operation in processor test: - Process holder @return changes.result_changes and process response """ changes = ProcessorChanges() biiout = OutputStream() processor.do_process(holder, changes, biiout) return changes, biiout
def test_basic_geom(self): block_cell_names = mother.make_folder_resources('dummy', 'virtual') self.block_holder = mother.get_block_holder(block_cell_names, CPP) changes = ProcessorChanges() VirtualConfigurationProcessor().do_process(self.block_holder, changes, OutputStream()) self.assertEqual(0, len(changes.upserted)) self.assertEqual(8, len(self.block_holder.cell_names)) self.check_virtual_resource('sphere.cpp') self.check_virtual_resource('sphere.h')
def test_process_config_file_with_unknown_deps(self): my_conf = '''r1.h + r9.cpp''' block_holder = self._prepare_context(my_conf) block_holder[self.r1.cell_name].cell.dependencies.implicit.add(self.r2) changes = ProcessorChanges() biiout = OutputStream() self.processor.do_process(block_holder, changes, biiout) self.assertIn('There are no files matching pattern r9.cpp', str(biiout)) self.assertEqual(0, len(changes.upserted)) r1 = block_holder[self.r1.cell_name].cell self.assertEqual({self.r2}, r1.dependencies.implicit)
def update(self, block_name=None, time=None): """ a block is outdated, because someone has published from another location, and parent is not the last one in the block anymore. update is able to merge with the given time param time: Can be None=> means the last one param block_name: The block to be updated """ from biicode.common.diffmerge.update import update hive_holder = self.hive_holder # TODO: Copied from publish: refactor if block_name is None: blocks = hive_holder.blocks if len(blocks) == 1: block_name = iter(blocks).next() else: raise BiiException('More than one block in this project %s\n' 'Please specify block to update\n' 'with "$ bii update my_user/my_block"') try: block_holder = hive_holder[block_name] except KeyError: raise BiiException("Block %s is not open" % block_name) files, other_version = update(block_holder, time, self._biiapi, self._biiout) # Extra "process" after the update proc_changes = ProcessorChanges() checkin_block_files(hive_holder, block_name, files, proc_changes, self._biiout) blocks_process(hive_holder, proc_changes, self._biiout) deps_process(self._biiapi, hive_holder, proc_changes, self._biiout) block_holder = hive_holder[block_name] block_holder.parent = other_version new_config = block_holder.commit_config() if new_config: proc_changes.upsert(new_config.name, new_config.content, True) self._edition.save_hive_changes(hive_holder.hive, proc_changes) return block_name
def test_has_main_and_dependency_declarations(self): processor = ParseProcessor() changes = ProcessorChanges() block_holder = mother.get_block_holder(['user/geom/main.cpp'], CPP) processor.do_process(block_holder, changes, OutputStream()) main = block_holder['main.cpp'].cell self.assertTrue(main.hasMain, 'Main method not detected by parse processor') self.check_dependency_set(main.dependencies, unresolved=['iostream', 'sphere.h']) # now remove #include load = block_holder['main.cpp'].content.load load.replace('#include "sphere.h"', '') block_holder['main.cpp'].content.load = load processor.do_process(block_holder, changes, OutputStream()) self.check_dependency_set(main.dependencies, unresolved=['iostream'])
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) changes = ProcessorChanges() VirtualConfigurationProcessor().do_process(self.block_holder, changes, OutputStream()) self._sphere_os_checks('sphere.h') self._sphere_os_checks('sphere.cpp') self.assertEqual(4, len(changes.upserted)) self.assertEqual(None, self.block_holder['sphere.h'].content) self.assertEqual(None, self.block_holder['sphere.cpp'].content)
def simple_dependencies_node_test(self): block_holder = self._cells_setup( 'dummy/geom', ['spherefun.js', 'sphere.js', 'main.js', 'other.js'], JS) # Parse processor setup block_holder['main.js'].cell.dependencies.unresolved = { NodeDeclaration('http.js'), NodeDeclaration('./sphere.js'), NodeDeclaration('other.js') } block_holder['sphere.js'].cell.dependencies.unresolved = { NodeDeclaration('http.js'), NodeDeclaration('url.js'), NodeDeclaration('./spherefun.js') } changes, _ = process_holder(block_holder, DependenciesProcessor()) # Checks self.assert_bii_equal(changes, ProcessorChanges()) mainR = block_holder['main.js'].cell self.assertEqual(mainR.dependencies.explicit, {'dummy/geom/sphere.js'}) self.assertEqual(mainR.dependencies.system, {'http.js'}) self.assertEqual( mainR.dependencies.resolved, {NodeDeclaration('http.js'), NodeDeclaration('./sphere.js')}) self.assertEqual(mainR.dependencies.unresolved, {NodeDeclaration('other.js')}) sphereR = block_holder['sphere.js'].cell self.assertEqual(sphereR.dependencies.explicit, {'dummy/geom/spherefun.js'}) self.assertEqual(sphereR.dependencies.system, {'http.js', 'url.js'}) self.assertEqual( sphereR.dependencies.resolved, { NodeDeclaration('http.js'), NodeDeclaration('url.js'), NodeDeclaration('./spherefun.js') }) self.assertEqual(sphereR.dependencies.unresolved, set())
def test_apply_result(self): # TODO: this is actually a test of find result, move away files = { self.block_name + 'main.cpp': '#include "user2/block/sphere.h"' } self.hive_manager.process(None, files) find_result = FinderResult() version = BRLBlock('user2/user2/block/branch') + 3 d = ReferencedDependencies() decl = CPPDeclaration('user2/block/sphere.h') d[version][decl].add(BlockCellName('user2/block/sphere.h')) find_result.resolved = d processor_changes = ProcessorChanges() hive_holder = self.hive_manager.hive_holder update_hive_with_find_result(hive_holder, find_result, processor_changes) self.assertEqual(2, len(hive_holder.resources)) self.assertEqual(BlockVersionTable([version]), hive_holder[self.block_name].requirements)
def close_block(hive_holder, block_name): block_version = hive_holder[block_name].parent processor_changes = ProcessorChanges() _delete_block(hive_holder, block_name, processor_changes) _update_requirements(hive_holder, block_version, processor_changes) return processor_changes