def _process_virtual_config(self, block_name, virtual, virtuals, realizations, biiout): '''Params: block_name : BlockName virtual: dictionary ''' for virtual_parse_result in virtual.itervalues(): for cell_name in virtual_parse_result.apply: block_cell_name = block_name + cell_name try: old_cell = self.block_holder[cell_name].cell except KeyError: old_cell = None #Build a new virtual cell with the new data, keeping old if existing new_cell = VirtualCell(block_cell_name, virtual_parse_result.code, virtual_parse_result.leaves) if old_cell is None: new_cell.type = BiiType.from_extension(block_cell_name.extension) else: new_cell.type = old_cell.type virtual_resource = Resource(new_cell, None) self.block_holder.add_resource(virtual_resource) self._process_leaves(new_cell, realizations, biiout) virtuals.add(block_cell_name)
def virtual_dependencies_test(self): sphereh = 'dummy/geom/sphere.h' sphereh_test = 'dummy/geom/test/sphere.h' sphereh_dev = 'dummy/geom/develop/sphere.h' block_holder = self._cells_setup( 'dummy/geom', ['main.cpp', 'test/sphere.h', 'main2.cpp', 'develop/sphere.h'], CPP) block_holder._resources['sphere.h'] = Resource(VirtualCell(sphereh), None) block_holder['test/sphere.h'].cell.container = BlockCellName(sphereh) block_holder['develop/sphere.h'].cell.container = BlockCellName( sphereh) block_holder['main.cpp'].cell.dependencies.unresolved = { CPPDeclaration(sphereh_test) } block_holder['main2.cpp'].cell.dependencies.unresolved = { CPPDeclaration(sphereh_dev) } _, outputstream = process_holder(block_holder, DependenciesProcessor()) warn = 'Block dummy/geom has absolute paths, like: #include "dummy/geom/develop/sphere.h"' self.assertIn(warn, str(outputstream)) # Checks main_cell = block_holder['main.cpp'].cell self.check_dependency_set(main_cell.dependencies, resolved=[sphereh_test], explicit=[sphereh]) main_cell = block_holder['main2.cpp'].cell self.check_dependency_set(main_cell.dependencies, resolved=[sphereh_dev], explicit=[sphereh])
def parse_virtual_test(self): response = OutputStream() cell = VirtualCell('usr/block/sort_controllers.py') resource = Resource(cell, None) self.assertFalse(resource.parse(response)) self.assertIn( 'You\'re trying to parse a virtual file: usr/block/sort_controllers.py', str(response))
class VirtualResourceTest(unittest.TestCase): def setUp(self): funcion = 'def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n\telse: return "nix"' self.r = VirtualCell('user/module/path/to/file.h', funcion) def testBasic(self): s = Settings() s.os.family = OSFamily('Linux') self.assertEqual('user/module/path/to/nix/file.h', self.r.evaluate(s)) s.os.family = OSFamily('Windows') self.assertEqual('user/module/path/to/win/file.h', self.r.evaluate(s)) #print self.r.leaves def testSerialize(self): serial = self.r.serialize() d = CellDeserializer(BlockCellName) deserialized = d.deserialize(serial) self.assertEquals(self.r, deserialized)
def virtual_test(self): references = References() references[va].add('a.h') code = ( 'def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n' '\telse: return "nix"') a = Resource(VirtualCell('user/blocka/a.h', code, {'win', 'nix'})) awin = Resource(SimpleCell('user/blocka/win/a.h')) anix = Resource(SimpleCell('user/blocka/nix/a.h')) b = Resource(SimpleCell('user/blockb/b.h')) d1 = Resource(SimpleCell('user/blockd/d.h')) awin.cell.dependencies.explicit.add(b.name) anix.cell.dependencies.explicit.add(d1.name) tables = {va: [vb, vd1], vb: [], vd1: []} api = FakeApi(zip([va, va, va, vb, vd1], [a, awin, anix, b, d1]), tables) #With windows settings settings = Settings(OSInfo(OSFamily("Windows"))) biiout = OutputStream() graph, closure, _ = build_closure(api, references, {}, settings, biiout) expected_graph = BlockVersionGraph() expected_graph.add_nodes([va, vb]) expected_graph.add_edge(va, vb) self.assertEqual(expected_graph, graph) expected_closure = Closure({ a.name: ClosureItem(a, va), awin.name: ClosureItem(awin, va), b.name: ClosureItem(b, vb), }) self.assertEqual(expected_closure, closure) self.assertEqual("", str(biiout)) #Change settings settings = Settings(OSInfo(OSFamily("Linux"))) biiout = OutputStream() graph, closure, _ = build_closure(api, references, {}, settings, biiout) expected_graph = BlockVersionGraph() expected_graph.add_nodes([va, vd1]) expected_graph.add_edge(va, vd1) self.assertEqual(expected_graph, graph) expected_closure = Closure({ a.name: ClosureItem(a, va), anix.name: ClosureItem(anix, va), d1.name: ClosureItem(d1, vd1), }) self.assertEqual(expected_closure, closure) self.assertEqual("", str(biiout))
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)
def test_virtual_cell(self): v = VirtualCell(BlockCellName('user/block/virtual.h'), "code", {"win", "nix"}) s = v.serialize() v2 = CellDeserializer(BlockCellName).deserialize(s) self.assertEqual(v, v2)
def setUp(self): funcion = 'def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n\telse: return "nix"' self.r = VirtualCell('user/module/path/to/file.h', funcion)