Esempio n. 1
0
    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])
Esempio n. 2
0
 def test_normalize_declaration_package_and_index(self):
     cut = NodeDeclaration("fran/noderedis")
     block_cell_names = [
         BlockCellName("fran/noderedis/index.js"),
         BlockCellName("fran/noderedis/package.json")
     ]
     self.assertEquals(cut, cut.normalize(block_cell_names))
Esempio n. 3
0
    def test_diamond_single_solution(self):
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        brl_b = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockb'))
        brl_c = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockc'))
        name_a = BlockCellName(self.user + "/blocka/a.h")
        publisher = TestPublisher(self.user, self.store)
        for _ in range(20):
            publisher.publish(brl_a, {'a.h': ('a', [])})

        name_b = BlockCellName(self.user + "/blockb/b.h")
        name_c = BlockCellName(self.user + "/blockc/c.h")

        for i in range(0, 20):
            if i % 2 == 0:
                publisher.publish(brl_b, {'b.h': ('b', [name_a])},
                                  dep_versions=BlockVersion(brl_a, i))
            if (i % 2 == 1 or i == 10):
                publisher.publish(brl_c, {'c.h': ('c', [name_a])},
                                  dep_versions=BlockVersion(brl_a, i))

        request = self.build_unresolved_request([name_b, name_c])
        result = self.service.find(request, BiiResponse())
        self.check_result(result,
                          resolved=[(brl_b, 5, {name_b}),
                                    (brl_c, 5, {name_c})])
 def test_init_match(self):
     sut = PythonDeclaration("import biicode.common.edition")
     block_cell_names = set([
         BlockCellName("biicode/common/__init__.py"),
         BlockCellName("biicode/common/edition.py")
     ])
     self.assertEquals(block_cell_names, sut.match(block_cell_names))
Esempio n. 5
0
 def test_simple_match(self):
     sut = JavaDeclaration("biicode.common.Edition")
     block_cell_names = set([
         BlockCellName("biicode/common/Edition.java"),
         BlockCellName("biicode/common/Jarl.java")
     ])
     self.assertEquals(set([BlockCellName("biicode/common/Edition.java")]),
                       sut.match(block_cell_names))
Esempio n. 6
0
    def test_rw_multi_contents(self):
        rid1 = BlockCellName("dummy/geom/sphere.cpp")
        cell1 = mother.make_content(rid1)
        rid2 = BlockCellName("dummy/geom/sphere.h")
        cell2 = mother.make_content(rid2)

        self.db.upsert_edition_contents([cell1, cell2])
        retrieved1 = self.db.read_edition_contents()
        self.assertEquals({rid1: cell1, rid2: cell2}, retrieved1)
Esempio n. 7
0
    def test_implementation_from_files(self, header, source):
        '''basic check that header is implemented by source'''
        sources = [header, source]
        block_holder = self._process_from_files(sources)

        header = BlockCellName(header)
        source = BlockCellName(source)
        header_cell = block_holder[header.cell_name].cell
        self.assertEqual({source}, header_cell.dependencies.implicit)
Esempio n. 8
0
    def test_same_path_relative_index_require(self):
        cut = NodeDeclaration("./")
        origin_block_cell_name = BlockCellName("fran/noderedis/bench.js")
        block_cell_names = [
            BlockCellName("fran/noderedis/index.js"),
            BlockCellName("fran/noderedis/client.js")
        ]

        m = cut.match(block_cell_names, origin_block_cell_name)
        self.assertItemsEqual(set(["fran/noderedis/index.js"]), m)
Esempio n. 9
0
    def test_match_with_implicit_require(self):
        cut = NodeDeclaration("fran/noderedis")

        block_cell_names = [
            BlockCellName("fran/noderedis/index.js"),
            BlockCellName("fran/noderedis/other.js")
        ]

        self.assertItemsEqual(set([BlockCellName("fran/noderedis/index.js")]),
                              cut.match(block_cell_names))
Esempio n. 10
0
    def test_package_json_recognition(self):
        cut = NodeDeclaration("fran/noderedis")

        block_cell_names = [
            BlockCellName("fran/noderedis/package.json"),
            BlockCellName("fran/noderedis/other.js")
        ]

        self.assertItemsEqual(
            set([BlockCellName("fran/noderedis/package.json")]),
            cut.match(block_cell_names))
Esempio n. 11
0
    def check_dependency_set(self,
                             dependencies,
                             explicit=None,
                             implicit=None,
                             data=None,
                             system=None,
                             resolved=None,
                             unresolved=None,
                             declaration=CPPDeclaration):
        '''custom assertion to check DependencySet
        system is a list of strings ['iostream', 'math.h']
        resolved is a iterable of strings 'user/module/file.h, 'iostream.h'.
        If None, will be computed from system+explicit
        unresolved is similar to resolved, but names can be shorter, as are not resolved
        unresolved {'sphere.h': Type:EXCPLICIT_CODE}'''

        system = system or set()
        explicit = explicit or set()
        implicit = implicit or set()
        data = data or set()
        unresolved = unresolved or set()
        if not resolved:
            resolved = set(copy.copy(system))
            resolved.update(explicit)

        systemDeps = set([SystemCellName(s) for s in system])
        self.assertEqual(systemDeps, dependencies.system,
                         'System dependencies do not match.\n\tExpected: %s\n\tObtained: %s' \
                         % (systemDeps, dependencies.system))

        explicitDeps = set([BlockCellName(s) for s in explicit])
        self.assertEqual(explicitDeps, dependencies.explicit,
                         'Explicit dependencies do not match.\n\tExpected: %s\n\tObtained: %s' \
                         % (explicitDeps, dependencies.explicit))

        dataDeps = set([BlockCellName(s) for s in data])
        self.assertEqual(dataDeps, dependencies.data,
                         'Data dependencies do not match.\n\tExpected: %s\n\tObtained: %s' \
                         % (dataDeps, dependencies.data))

        implicitDeps = set([BlockCellName(s) for s in implicit])
        self.assertEqual(implicitDeps, dependencies.implicit,
                         'Implicit dependencies do not match.\n\tExpected: %s\n\tObtained: %s' \
                         % (implicitDeps, dependencies.implicit))

        unresolvedDeps = set([declaration(name) for name in unresolved])
        self.assertEqual(unresolvedDeps, dependencies.unresolved,
                         'Unresolved dependencies do not match.\n\tExpected: %s\n\tObtained: %s' \
                         % (unresolvedDeps, dependencies.unresolved))

        resolvedDeps = set([declaration(name) for name in resolved])
        self.assertEqual(resolvedDeps, dependencies.resolved,
                         'Resolved dependencies do not match.\n\tExpected %s\n\tObtained: %s' \
                         % (resolvedDeps, dependencies.resolved))
Esempio n. 12
0
    def test_simple_match_relative_in_different_block(self):
        sut = PythonDeclaration("from edition import *")

        block_cell_names = set([
            BlockCellName("biicode/parsing/edition.py"),
            BlockCellName("biicode/parsing/jarl.py")
        ])

        from_block_cell_name = BlockCellName("biicode/common/main.py")
        self.assertEquals(set(),
                          sut.match(block_cell_names, from_block_cell_name))
Esempio n. 13
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
Esempio n. 14
0
    def test_dependency_set(self):
        d1 = DependencySet()
        d1.add_implicit(BlockCellName("user/block/path/file2.h"))
        d1.add_implicit(BlockCellName("user/block/path/file3.h"))
        d1.add_implicit(BlockCellName("user/block/path/file4.h"))
        names = set()
        names.add(CPPDeclaration("iostream.h"))
        d1.update_declarations(names)

        s = d1.serialize()
        d2 = DependencySet.deserialize(s)
        self.assert_bii_equal(d1, d2)
Esempio n. 15
0
    def test_no_matched_config_relpath(self):
        cut = CMakeDeclaration("../config")
        origin_block_cell_name = BlockCellName(
            "fran/cmakeparsing/other/thing/start.cmake")

        block_cell_names = [
            BlockCellName("fran/cmakeparsing/CMakeLists.txt"),
            BlockCellName("fran/cmakeparsing/other/thing/macro.cmake"),
            BlockCellName("fran/cmakeparsing/config")
        ]

        self.assertItemsEqual(
            set(), cut.match(block_cell_names, origin_block_cell_name))
Esempio n. 16
0
    def test_relative_require_not_found(self):
        cut = NodeDeclaration("../parser")
        origin_block_cell_name = BlockCellName(
            "fran/noderedis/other/thing/other.js")

        block_cell_names = [
            BlockCellName("fran/noderedis/index.js"),
            BlockCellName("fran/noderedis/other/thing/other.js"),
            BlockCellName("fran/noderedis/parser.js")
        ]

        self.assertItemsEqual(
            set(), cut.match(block_cell_names, origin_block_cell_name))
Esempio n. 17
0
    def test_one_level_relative_require_with_depth(self):
        cut = NodeDeclaration("./lib/parser/queue")
        origin_block_cell_name = BlockCellName("fran/noderedis/index.js")

        block_cell_names = [
            BlockCellName("fran/noderedis/index.js"),
            BlockCellName("fran/noderedis/lib/queue.js"),
            BlockCellName("fran/noderedis/lib/parser/queue.js")
        ]

        self.assertItemsEqual(
            set(["fran/noderedis/lib/parser/queue.js"]),
            cut.match(block_cell_names, origin_block_cell_name))
Esempio n. 18
0
    def test_match_with_macro_cmake_abspath(self):
        cut = CMakeDeclaration("fran/cmakeparsing/cmake/Macros_2.cmake")
        origin_block_cell_name = BlockCellName(
            "fran/cmakeparsing/CMakeLists.txt")

        block_cell_names = [
            BlockCellName("fran/cmakeparsing/CMakeLists.txt"),
            BlockCellName("fran/cmakeparsing/cmake/Macros.cmake"),
            BlockCellName("fran/cmakeparsing/cmake/Macros_2.cmake")
        ]

        self.assertItemsEqual(
            set(["fran/cmakeparsing/cmake/Macros_2.cmake"]),
            cut.match(block_cell_names, origin_block_cell_name))
Esempio n. 19
0
    def test_simple_edition_cell_with_container(self):
        virtual_cell = BlockCellName('user/block/path/file.h')
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = BlockCellName("user/block/path/to/file.h")
        simpleresource.root = ID()
        simpleresource.dependencies.add_implicit(
            BlockCellName("user/block/path/file.h"))
        simpleresource.container = virtual_cell

        s = simpleresource.serialize()

        self.assertEqual(s[Deserializer.POLIMORPHIC_KEYWORD],
                         ClassTypedSerializer.getValue(SimpleCell))
        ob = CellDeserializer(BlockCellName).deserialize(s)
        self.assert_bii_equal(ob, simpleresource)
Esempio n. 20
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
Esempio n. 21
0
    def test_relative_composed_block_match(self):
        #Given
        cut = CPPDeclaration("algs/astar.h")
        from_block_cell_name = BlockCellName('fran/test/main.cpp')
        block_cell_names = [
            BlockCellName("fran/test/algs/astar.h"),
            BlockCellName("fran/test/main.cpp")
        ]

        #When
        result = cut.match(block_cell_names, from_block_cell_name)

        #Then
        expected = set([BlockCellName('fran/test/algs/astar.h')])
        self.assertEquals(result, expected)
def publish_pack_add(pack, block_cell_name, content_text):
    name = BlockCellName(block_cell_name)
    cell1 = SimpleCell(name)
    pack.cells.add(cell1)
    pack.contents[name.cell_name] = Content(
        load=Blob(content_text))  # it MUST have a content to be deleted
    return cell1
Esempio n. 23
0
    def test_find_two_files_at_a_time(self):
        """Starts with one include, finds it, then two more includes, finish when all are found.
        Found items are taken into account in FindRequest.existing
        """

        NUM_FILES = 10
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        names_a = [
            BlockCellName(self.user + "/blocka/a%d.h" % i)
            for i in range(NUM_FILES)
        ]
        resources_info = {"a%d.h" % i: ("a", []) for i in range(NUM_FILES)}
        publisher = TestPublisher(self.user, self.store)
        publisher.publish(brl_a, resources_info)
        # Use the same request object, to accumulate existing (already found) files
        request = FinderRequest()
        request.policy = Policy.default()
        version = BlockVersion(brl_a, 0)  # The version is always the same
        for i in range(0, NUM_FILES, 2):
            declaration1 = CPPDeclaration(names_a[i])
            declaration2 = CPPDeclaration(names_a[i + 1])
            request.unresolved = {declaration1, declaration2}
            result = self.service.find(request, BiiResponse())
            self.check_result(result,
                              resolved=[(brl_a, 0,
                                         {names_a[i], names_a[i + 1]})])
            # The found one is added to the existing, for next iteration
            request.existing[version][declaration1] = {names_a[i]}
            request.existing[version][declaration2] = {names_a[i + 1]}
            self.assertEqual(len(request.existing[version]), i + 2)
Esempio n. 24
0
def make_published_resource(block, block_cell_name):
    if isinstance(block_cell_name, basestring):
        moduleCellName = BlockCellName(block_cell_name)
    sr = SimpleCell(block_cell_name)
    sr.type = BiiType.from_extension(moduleCellName.extension)
    sr.ID = UserID(1) + 1 + 2
    return sr
Esempio n. 25
0
    def test_deps_block_match(self):
        #Given
        cut = CPPDeclaration("../../deps/akka/math/sphere.h")
        from_block_cell_name = BlockCellName('fran/test/main.cpp')
        block_cell_names = [
            BlockCellName("akka/math/sphere.h"),
            BlockCellName("fran/test/other/jarl.cpp"),
            BlockCellName("fran/test/main.cpp")
        ]

        #When
        result = cut.match(block_cell_names, from_block_cell_name)

        #Then
        expected = set([BlockCellName('akka/math/sphere.h')])
        self.assertEquals(result, expected)
Esempio n. 26
0
    def test_find_transitive(self):
        '''Test including a block with other dependencies, without conflicts '''
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        name_a = BlockCellName(self.user + "/blocka/a.h")
        publisher = TestPublisher(self.user, self.store)
        publisher.publish(brl_a, {'a.h': ('a', [])})

        brl_b = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockb'))
        name_b = BlockCellName(self.user + "/blockb/b.h")
        #self.publish(brl_b, name_b, deps={name_b: name_a}, dep_versions=BlockVersion(brl_a, 0))
        publisher.publish(brl_b, {'b.h': ('b', [name_a])},
                          dep_versions=BlockVersion(brl_a, 0))

        request = self.build_unresolved_request(name_b)
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(brl_b, 0, {name_b})])
Esempio n. 27
0
 def _getBlockCellNames(self, dim):
     '''generates names from dim list'''
     bcns = [
         BlockCellName(self.testUser.ID + '/module%s/cell%s' % (i, i))
         for i in range(len(dim))
     ]
     return bcns
Esempio n. 28
0
 def order_paths(target):
     include_paths = []
     blocks = hive_holder.blocks
     for key in sorted(target.include_paths.iterkeys()):
         path = target.include_paths[key]
         try:
             current_block = BlockCellName("%s/dummy" % path).block_name
         except:  # Not able to build block_name, it should be only username
             origins = [DEP_DIR, SRC_DIR]
             current_block = "&*NoBlock%$"
         else:
             origins = [SRC_DIR if current_block in blocks else DEP_DIR]
         for src in origins:
             if src == SRC_DIR:
                 rel_path = bii_paths.blocks_relative
             else:
                 rel_path = bii_paths.deps_relative
             if root_block == current_block:
                 # remove the initial BlockName from path
                 cmake_path = '${BII_PROJECT_ROOT}/%s' % path[len(current_block):]
             else:
                 cmake_path = '${BII_PROJECT_ROOT}/%s/%s' % (rel_path, path)
             if cmake_path not in include_paths:
                 include_paths.append(cmake_path)
     target.include_paths = include_paths
Esempio n. 29
0
    def test_cell(self):
        brl = BlockCellName("drodri/pang/test.cpp")
        r = SimpleCell(brl)

        self.assertFalse(r.hasMain)
        self.assertEquals(r.name, brl)
        self.assertEquals(r.type, UNKNOWN)
Esempio n. 30
0
 def block(self):
     python_import = self.python_import()
     try:
         return BlockCellName(normalized_name(
             python_import.module)).block_name
     except:
         return None
Esempio n. 31
0
    def testDeserializeDict(self):
        brl = BlockCellName("user/block/path/file.h")
        brl2 = BlockCellName("user/block/path/file2.h")

        h = {brl.serialize(): "asasdasdasd",
             brl2.serialize(): "1123"
        }
        ret = DictDeserializer(BlockCellName, str).deserialize(h)
        self.assertEqual(ret, {'user/block/path/file.h': 'asasdasdasd',
                               'user/block/path/file2.h': '1123'})

        h = {brl.serialize(): brl.serialize(),
             brl2.serialize(): brl.serialize()
        }

        ret = DictDeserializer(BlockCellName, BlockCellName).deserialize(h)
        self.assertEqual(ret,
                         {'user/block/path/file.h': 'user/block/path/file.h',
                          'user/block/path/file2.h': 'user/block/path/file.h'}
                        )
 def test_block_cell_name(self):
     b = BlockCellName("user/block/path/file.h")
     s = b.serialize()
     b2 = BlockCellName.deserialize(s)
     self.assertEqual(b, b2)