Exemple #1
0
 def test_serialize_policy(self):
     p = Policy.loads(policy_yaml)
     self.assertEqual(p[0].tag, ALPHA)
     self.assertEqual(p[0].block, "diego/geom2(branch1)")
     self.assertEqual(p[1].tag, BETA)
     self.assertEqual(p[1].block, "diego/geom")
     d = p.serialize()
     p2 = Policy.deserialize(d)
     self.assertEqual(p, p2)
    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)
    def test_compute_request(self):
        files = {self.block_name + 'main.cpp': '#include "user2/block/sphere.h"'}
        self.hive_manager.process(None, files)

        find_request, unresolved = self.hive_manager.hive_holder.find_request(Policy.default())
        self.assertIn(CPPDeclaration('user2/block/sphere.h'), find_request.unresolved)
        self.assertEqual(unresolved, set())
    def test_no_unresolved_to_local(self):
        files = {self.block_name + 'main.cpp': '#include "dummy/myblock/sphere.h"'}
        self.hive_manager.process(None, files)

        find_request, unresolved = self.hive_manager.hive_holder.find_request(Policy.default())
        self.assertEqual(set(), find_request.unresolved)
        self.assertEqual(unresolved, {CPPDeclaration("dummy/myblock/sphere.h")})
 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)
Exemple #6
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)
 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
 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
 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)
Exemple #10
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
Exemple #11
0
    def test_evaluate(self):
        p = Policy.loads(policy_yaml)
        m = BlockVersion(BRLBlock('diego/diego/geom/master'), 3)
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('diego/diego/geom2/branch1'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('diego2/diego2/geom3/branch1'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('anyuser/diego2/geom3/anybranch'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('anyuser/diego2/geom4/anybranch'), 4)
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, BETA))
        self.assertEqual(False, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('pepe/diego2/geom4/anybranch'), 4)
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('pepe/john/geom4/anybranch'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))

        p = Policy.loads("*: DEV")
        m = BlockVersion(BRLBlock('diego/diego/geom/master'), 3)
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
Exemple #12
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
Exemple #13
0
    def find(self, policy=None, **find_args):
        # Imports are local, cause only used in this function, avoid loading modules for
        # every execution
        from biicode.common.find import find_manager
        from biicode.common.find.policy import Policy

        policy = policy or Policy.default()

        hive_holder = self.hive_holder
        return find_manager.find(self._biiapi, hive_holder, self._biiout, policy, **find_args)
Exemple #14
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
Exemple #15
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
    def test_tag_policy_update(self):
        for i, tag in enumerate([BETA, ALPHA, DEV]):
            # Do not update
            request = self.build_update_request(BlockVersion(self.brl, i), self.name)
            result = self.service.find(request, BiiResponse())
            self.check_result(result)

            # update
            request.policy = Policy.loads("*: %s" % tag)
            result = self.service.find(request, BiiResponse())
            self.check_result(result, updated=[(self.brl, i + 1, {self.name})])
Exemple #17
0
    def test_no_unresolved_to_local(self):
        files = {
            self.block_name + 'main.cpp': '#include "dummy/myblock/sphere.h"'
        }
        self.hive_manager.process(None, files)

        find_request, unresolved = self.hive_manager.hive_holder.find_request(
            Policy.default())
        self.assertEqual(set(), find_request.unresolved)
        self.assertEqual(unresolved,
                         {CPPDeclaration("dummy/myblock/sphere.h")})
Exemple #18
0
    def test_compute_request(self):
        files = {
            self.block_name + 'main.cpp': '#include "user2/block/sphere.h"'
        }
        self.hive_manager.process(None, files)

        find_request, unresolved = self.hive_manager.hive_holder.find_request(
            Policy.default())
        self.assertIn(CPPDeclaration('user2/block/sphere.h'),
                      find_request.unresolved)
        self.assertEqual(unresolved, set())
Exemple #19
0
 def deserialize(data):
     '''From dictionary to object FinderRequest'''
     ret = FinderRequest()
     ret.block_names = SetDeserializer(BlockName).deserialize(data[FinderRequest.SERIAL_TRACKING_KEY])
     ret.existing = ReferencedDependencies.deserialize(data[FinderRequest.SERIAL_EXISTING_KEY])
     ret.unresolved = SetDeserializer(Declaration).deserialize(data[FinderRequest.SERIAL_UNRESOLVED_KEY])
     ret.policy = Policy.deserialize(data[FinderRequest.SERIAL_POLICY])
     criteria = data[FinderRequest.SERIAL_CRITERIA]
     ret.find, ret.update, ret.downgrade, ret.modify = criteria
     ret.existing_common_table = BlockVersionTable.deserialize(data[FinderRequest.SERIAL_DEP_COMMON_TABLE])
     return ret
    def test_tag_policy_find(self):
        """ change tag policy to find BETA and DEV """
        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: BETA")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 1, {self.name})])

        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: ALPHA")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 2, {self.name})])

        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: DEV")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 3, {self.name})])

        request = self.build_unresolved_request(self.name)
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 0, {self.name})])
Exemple #21
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)
Exemple #22
0
 def test_errors(self):
     with self.assertRaisesRegexp(BiiException, "Incorrect rule in policies.bii"):
         Policy.loads("*: ALFA")
     with self.assertRaisesRegexp(BiiException, "Incorrect rule in policies.bii"):
         Policy.loads("what")
     with self.assertRaisesRegexp(BiiException, "Empty policies.bii, cannot find"):
         Policy.loads("#adasd\n#asdasd\n")
    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)
Exemple #25
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn("Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies
Exemple #26
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn(
                     "Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies