def test_finder_request_unresolved(self):
     f = FinderRequest()
     f.unresolved = set([CPPDeclaration("iostream.h"), CPPDeclaration("math.h")])
     f.policy = Policy.default()
     s = f.serialize()
     f2 = FinderRequest.deserialize(s)
     self.assertEqual(f, f2)
Пример #2
0
 def test_find_one_file_at_a_time(self):
     '''Starts with one include, finds it, then put another include, 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'))
     publisher = TestPublisher(self.user, self.store)
     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.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(NUM_FILES):
         declaration = CPPDeclaration(names_a[i])
         request.unresolved = {declaration}
         result = self.service.find(request, BiiResponse())
         self.check_result(result, resolved=[(brl_a, 0, {names_a[i]})])
         # The found one is added to the existing, for next iteration
         request.existing[version][declaration] = {names_a[i]}
         self.assertEqual(len(request.existing[version]), i + 1)
    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)
Пример #4
0
 def _unresolvedDependencyRequest(self, unresolved_deps):
     request = FinderRequest()
     unresolved = set()
     for dep in unresolved_deps:
         unresolved.add(CPPDeclaration(dep))
     request.unresolved = unresolved
     request.policy = Policy.default()
     return request
Пример #5
0
 def _unresolvedDependencyRequest(self, unresolved_deps):
     request = FinderRequest()
     unresolved = set()
     for dep in unresolved_deps:
         unresolved.add(CPPDeclaration(dep))
     request.unresolved = unresolved
     request.policy = Policy.default()
     return request
Пример #6
0
 def build_update_request(self, block_version, block_cell_name):
     request = FinderRequest()
     existing = ReferencedDependencies()
     existing[block_version][CPPDeclaration(block_cell_name)].add(block_cell_name)
     request.existing = existing
     request.policy = Policy.default()
     request.find = False
     request.update = True
     return request
Пример #7
0
 def build_unresolved_request(self, unresolved_deps):
     if isinstance(unresolved_deps, basestring):
         unresolved_deps = [unresolved_deps]
     request = FinderRequest()
     unresolved = set()
     for dep in unresolved_deps:
         unresolved.add(CPPDeclaration(dep))
     request.unresolved = unresolved
     request.policy = Policy.default()
     return request
Пример #8
0
 def build_unresolved_request(self, unresolved_deps):
     if isinstance(unresolved_deps, basestring):
         unresolved_deps = [unresolved_deps]
     request = FinderRequest()
     unresolved = set()
     for dep in unresolved_deps:
         unresolved.add(CPPDeclaration(dep))
     request.unresolved = unresolved
     request.policy = Policy.default()
     return request
Пример #9
0
def find(auth_user, bson_data, response):
    service = BiiService(app.store, auth_user)

    # TODO: Remove this try except when next incompatible version
    try:
        finder_request = FinderRequest.deserialize(bson_data["data"])
    except KeyError:  # Keep some retro-compatibility with old policies format
        bson_data["data"][FinderRequest.SERIAL_POLICY] = Policy.default().serialize()
        finder_request = FinderRequest.deserialize(bson_data["data"])
        response.warn("Detected deprecated policy format (version < 2.7),"
                      "discarding them. Update biicode!")
    return service.find(finder_request, response)
Пример #10
0
 def find_request(self, policy):
     request = FinderRequest(policy)
     request.existing = self.external_dependencies()
     blocks = self.blocks
     # ONly those that have a block to be searched for
     unresolved = set()
     local_unresolved = set()
     for block_holder in self.block_holders:
         includes = block_holder.includes
         paths_size = len(block_holder.paths)
         for declaration in self.external_unresolved():
             try:
                 new_declaration, _ = declaration.prefix(includes, paths_size)
             except:
                 new_declaration = declaration
             decl_block = new_declaration.block()
             if decl_block and decl_block not in blocks:
                 unresolved.add(new_declaration)
             else:
                 local_unresolved.add(new_declaration)
     request.unresolved = unresolved
     request.block_names = self.blocks
     return request, local_unresolved
Пример #11
0
 def test_finder_request_unresolved(self):
     f = FinderRequest()
     f.unresolved = set(
         [CPPDeclaration("iostream.h"),
          CPPDeclaration("math.h")])
     f.policy = Policy.default()
     s = f.serialize()
     f2 = FinderRequest.deserialize(s)
     self.assertEqual(f, f2)
Пример #12
0
 def find_request(self, policy):
     request = FinderRequest(policy)
     request.existing = self.external_dependencies()
     blocks = self.blocks
     # ONly those that have a block to be searched for
     unresolved = set()
     local_unresolved = set()
     for block_holder in self.block_holders:
         includes = block_holder.includes
         paths_size = len(block_holder.paths)
         for declaration in self.external_unresolved():
             try:
                 new_declaration, _ = declaration.prefix(
                     includes, paths_size)
             except:
                 new_declaration = declaration
             decl_block = new_declaration.block()
             if decl_block and decl_block not in blocks:
                 unresolved.add(new_declaration)
             else:
                 local_unresolved.add(new_declaration)
     request.unresolved = unresolved
     request.block_names = self.blocks
     return request, local_unresolved
Пример #13
0
 def build_update_request(self, block_version, block_cell_name):
     request = FinderRequest()
     existing = ReferencedDependencies()
     existing[block_version][CPPDeclaration(block_cell_name)].add(
         block_cell_name)
     request.existing = existing
     request.policy = Policy.default()
     request.find = False
     request.update = True
     return request
Пример #14
0
    def test_fiunder_request_existing(self):
        f = FinderRequest()
        self.assertFalse(f)
        existing = ReferencedDependencies()
        version = BlockVersion('user/user/block/master', 1)
        existing[version][CPPDeclaration("file.h")].add(CellName("file.h"))
        f.existing = existing
        f.update = True
        f.policy = Policy.default()
        #print f
        s = f.serialize()
        #print s
        f2 = FinderRequest.deserialize(s)

        self.assertEquals(f, f2)
        self.assertTrue(f2)
    def test_fiunder_request_existing(self):
        f = FinderRequest()
        self.assertFalse(f)
        existing = ReferencedDependencies()
        version = BlockVersion('user/user/block/master', 1)
        existing[version][CPPDeclaration("file.h")].add(CellName("file.h"))
        f.existing = existing
        f.update = True
        f.policy = Policy.default()
        #print f
        s = f.serialize()
        #print s
        f2 = FinderRequest.deserialize(s)

        self.assertEquals(f, f2)
        self.assertTrue(f2)