Exemplo n.º 1
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)
Exemplo n.º 2
0
 def res_method(*args):
     depsb = [BlockCellName('user/blockA/a.h')]
     depsc = [BlockCellName('user/blockA/a.h')]
     result = ReferencedResources()
     for ref in args[0].explode():
         result[ref.block_version][ref.ref] = \
         {Reference(depA1, 'a.h'): ((0, 0), 0, []),
          Reference(depA2, 'a.h'): ((0, 0), 0, []),
          Reference(baseB, 'b.h'): ((1, 4), 1, depsb),
          Reference(baseC, 'c.h'): ((2, 3), 2, depsc)}[ref]
     return result
Exemplo n.º 3
0
        def res_method(*args):
            c_virtual_leaves = [BlockCellName('user/blockC/win/c.h'),
                                BlockCellName('user/blockC/nix/c.h')]
            c_win_deps = [BlockCellName('user/blockA/a.h')]
            c_nix_deps = [BlockCellName('user/blockB/b.h')]

            result = ReferencedResources()
            for ref in args[0].explode():
                result[ref.block_version][ref.ref] = \
                {Reference(depA, 'a.h'): ((0, 0), 0, []),
                 Reference(depB, 'b.h'): ((1, 1), 1, []),
                 Reference(baseC, 'c.h'): ((2, 2), 2, c_virtual_leaves),
                 Reference(baseC, 'win/c.h'): ((3, 3), 3, c_win_deps),
                 Reference(baseC, 'nix/c.h'): ((4, 4), 4, c_nix_deps)}[ref]
            return result
Exemplo n.º 4
0
    def test_build_closure_different_versions_restricted(self):
        '''Computes a CompatibilityClosure in which two versions of blockA actually point to the
        same unmodified resource with the typical diamond layout
        Also computes and checks the BlockClosure for that layout'''
        ref_translator = Mock()

        depA1 = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)
        depA2 = BlockVersion(BRLBlock('user/user/blockA/branch'), 5)
        baseB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        baseC = BlockVersion(BRLBlock('user/user/blockC/branch'), 3)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseB, baseC, depA1, depA2])
        full_graph.add_edge(baseB, depA1)
        full_graph.add_edge(baseC, depA2)

        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]
            depsc = [BlockCellName('user/blockA/a.h')]
            result = ReferencedResources()
            for ref in args[0].explode():
                result[ref.block_version][ref.ref] = \
                {Reference(depA1, 'a.h'): ((0, 0), 0, []),
                 Reference(depA2, 'a.h'): ((0, 0), 0, []),
                 Reference(baseB, 'b.h'): ((1, 4), 1, depsb),
                 Reference(baseC, 'c.h'): ((2, 3), 2, depsc)}[ref]
            return result

        ref_translator.get_published_min_refs.side_effect = res_method

        missing = References()
        missing.add(Reference(baseB, 'b.h'))
        missing.add(Reference(baseC, 'c.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, {baseC}, full_graph)

        self.assertEqual(References(), closure.broken)
        self.assertEqual({BlockCellName('user/blockC/c.h')}, closure.block_cell_names)
        #self.assertIn(Reference(depA1, 'a.h'), closure.references)
        self.assertNotIn(baseB, closure.references)
        self.assertNotIn(depA1, closure.references)
        self.assertNotIn(depA2, closure.references)
        self.assertIn(baseC, closure.references)
        expected_frontier = References()
        expected_frontier[baseB].add('b.h')
        expected_frontier[depA2].add('a.h')
        self.assertEqual(expected_frontier, closure.frontier)
Exemplo n.º 5
0
 def __init__(self, resources, tables):
     """ Input: {version: resource}
     """
     self._resources = {}  # {Reference: Resource}
     for version, resource in resources:
         self._resources[Reference(version, resource.cell_name)] = resource
     self._tables = {}
     for version, dep_versions in tables.iteritems():
         self._tables[version] = BlockVersionTable(dep_versions)
Exemplo n.º 6
0
        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]

            result = ReferencedResources()
            for ref in args[0].explode():
                try:
                    result[ref.block_version][ref.ref] = \
                    {
                     Reference(baseB, 'b.h'): ((0, 0), 0, depsb),
                     }[ref]
                except KeyError:
                    pass
            return result
Exemplo n.º 7
0
    def test_virtual_no_settings(self):
        '''builds a very simple closure in which virtual cells are involved. Maybe it is not very
        useful, as now virtuality is not handled at this level, only at the MemServerStore level,
        so this test might be redundant'''
        ref_translator, depA, depB, baseC, full_graph = self._virtual_setup()

        missing = References()
        missing.add(Reference(baseC, 'c.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, full_graph.nodes, full_graph)
        self.assertEqual(References(), closure.broken)

        self.assertEqual(set([BlockCellName('user/blockA/a.h'),
                              BlockCellName('user/blockB/b.h'),
                              BlockCellName('user/blockC/c.h'),
                              BlockCellName('user/blockC/win/c.h'),
                              BlockCellName('user/blockC/nix/c.h')]),
                              closure.block_cell_names)
Exemplo n.º 8
0
    def test_broken_closure(self):
        '''computes a closure in which cell blockB/b.h depends on blockA/a.h, but that a.h
        is not found. The algorithms of closures must return that as a missing or broken dependency

        '''
        ref_translator = Mock()
        baseB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        depA1 = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseB, depA1])
        full_graph.add_edge(baseB, depA1)

        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]

            result = ReferencedResources()
            for ref in args[0].explode():
                try:
                    result[ref.block_version][ref.ref] = \
                    {
                     Reference(baseB, 'b.h'): ((0, 0), 0, depsb),
                     }[ref]
                except KeyError:
                    pass
            return result

        ref_translator.get_published_min_refs.side_effect = res_method

        missing = References()
        missing.add(Reference(baseB, 'b.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, full_graph.nodes, full_graph)

        self.assertEqual({BlockCellName('user/blockB/b.h')}, closure.block_cell_names)
        self.assertIn(baseB, closure.references)

        expected_missing = References()
        expected_missing[depA1].add('a.h')
        self.assertEqual(closure.broken, expected_missing)
Exemplo n.º 9
0
    def _read_referenced_resources(self, query, id_type):
        statement = query

        ret = ReferencedResources()
        rs = statement.fetchall()
        cell_des = CellDeserializer(id_type)
        content_des = ContentDeserializer(id_type)
        for r in rs:
            try:
                v = Reference.deserialize(decode_serialized_value(r[0]))
                scontent = decode_serialized_value(r[2]) if r[2] else None
                res = Resource(cell_des.deserialize(decode_serialized_value(r[1])),
                               content_des.deserialize(scontent))
                cell_name = v.ref
                ret[v.block_version][cell_name] = res
                # logger.debug("Local found: %s/%s" % (str(v.block_version), str(cell_name)))
            except Exception as e:
                tb = traceback.format_exc()
                logger.error("Error while reading resources %s" % str(e))
                logger.debug(tb)

        return ret
Exemplo n.º 10
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)
Exemplo n.º 11
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())
Exemplo n.º 12
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))
Exemplo n.º 13
0
 def __add__(self, cell_name):
     '''Adding a BlockVersion+CellName gives as a Reference. This is a
     convenience method for easy creation of Reference, not intended for
     intensive creation use'''
     from biicode.common.model.symbolic.reference import Reference
     return Reference(self, cell_name)