def test_add_tree(self):
     forest = PackagesForest()
     tree = forest.add_tree(priority=10)
     self.assertIs(tree, forest.trees[10])
     # test that trees with the same priority are merged
     tree = forest.add_tree(priority=10)
     self.assertEqual(1, len(forest.trees))
     tree = forest.add_tree(priority=50)
     self.assertEqual(2, len(forest.trees))
Exemple #2
0
 def test_add_tree(self):
     forest = PackagesForest()
     tree = forest.add_tree(priority=10)
     self.assertIs(tree, forest.trees[10])
     # test that trees with the same priority are merged
     tree = forest.add_tree(priority=10)
     self.assertEqual(1, len(forest.trees))
     tree = forest.add_tree(priority=50)
     self.assertEqual(2, len(forest.trees))
Exemple #3
0
    def _get_packages(self, repos, requirements, include_mandatory):
        if requirements is not None:
            forest = PackagesForest()
            for repo in repos:
                self.controller.load_packages(repo, forest.add_tree().add)
            return forest.get_packages(requirements, include_mandatory)

        packages = set()
        self._load_packages(repos, packages.add)
        return packages
 def test_get_packages(self):
     forest = PackagesForest()
     self._generate_packages(forest)
     packages = forest.get_packages(
         [generator.gen_relation("package3")]
     )
     self.assertItemsEqual(
         ["package2", "package3", "package5"],
         (x.name for x in packages)
     )
 def test_find(self):
     forest = PackagesForest()
     p11 = generator.gen_package(name="package1", version=1)
     p12 = generator.gen_package(name="package1", version=2)
     p21 = generator.gen_package(name="package2", version=1)
     p22 = generator.gen_package(name="package2", version=2)
     p33 = generator.gen_package(name="package2", version=10)
     self._add_packages(forest.add_tree(priority=10), [p11, p22])
     self._add_packages(forest.add_tree(priority=10), [p12, p21])
     self._add_packages(forest.add_tree(priority=20), [p33])
     self.assertEqual(
         p11, forest.find(generator.gen_relation("package1", ["=", 1]))
     )
     self.assertEqual(
         p12, forest.find(generator.gen_relation("package1", [">=", 1]))
     )
     self.assertEqual(
         p12, forest.find(generator.gen_relation("package1", [">", 1]))
     )
     self.assertEqual(p22, forest.find(generator.gen_relation("package2")))
     self.assertEqual(
         p21, forest.find(generator.gen_relation("package2", ["<", 2]))
     )
     # select package from the repo with highest priority
     # p33 has version 10, but in the repo with lower priority
     self.assertEqual(
         p22, forest.find(generator.gen_relation("package2", [">=", 2]))
     )
Exemple #6
0
    def _get_packages(self, repos, requirements, include_mandatory,
                      exclude_filter):
        if requirements is not None:
            forest = PackagesForest()
            for repo in repos:
                self.controller.load_packages(repo, forest.add_tree().add)
            return forest.get_packages(requirements, include_mandatory)

        packages = set()
        consumer = packages.add
        if exclude_filter is not None:
            def consumer(p):
                if not exclude_filter(p):
                    packages.add(p)
        self._load_packages(repos, consumer)
        return packages
Exemple #7
0
    def _get_packages(self, repos, requirements, include_mandatory,
                      exclude_filter):
        if requirements is not None:
            forest = PackagesForest()
            for repo in repos:
                self.controller.load_packages(repo, forest.add_tree().add)
            return forest.get_packages(requirements, include_mandatory)

        packages = set()
        consumer = packages.add
        if exclude_filter is not None:

            def consumer(p):
                if not exclude_filter(p):
                    packages.add(p)

        self._load_packages(repos, consumer)
        return packages
Exemple #8
0
 def test_find(self):
     forest = PackagesForest()
     p11 = generator.gen_package(name="package1", version=1)
     p12 = generator.gen_package(name="package1", version=2)
     p21 = generator.gen_package(name="package2", version=1)
     p22 = generator.gen_package(name="package2", version=2)
     p33 = generator.gen_package(name="package2", version=10)
     self._add_packages(forest.add_tree(priority=10), [p11, p22])
     self._add_packages(forest.add_tree(priority=10), [p12, p21])
     self._add_packages(forest.add_tree(priority=20), [p33])
     self.assertEqual(
         p11, forest.find(generator.gen_relation("package1", ["=", 1])))
     self.assertEqual(
         p12, forest.find(generator.gen_relation("package1", [">=", 1])))
     self.assertEqual(
         p12, forest.find(generator.gen_relation("package1", [">", 1])))
     self.assertEqual(p22, forest.find(generator.gen_relation("package2")))
     self.assertEqual(
         p21, forest.find(generator.gen_relation("package2", ["<", 2])))
     # select package from the repo with highest priority
     # p33 has version 10, but in the repo with lower priority
     self.assertEqual(
         p22, forest.find(generator.gen_relation("package2", [">=", 2])))
 def test_find(self):
     forest = PackagesForest()
     p11 = generator.gen_package(name="package1", version=1)
     p12 = generator.gen_package(name="package1", version=2)
     p21 = generator.gen_package(name="package2", version=1)
     p22 = generator.gen_package(name="package2", version=2)
     self._add_packages(forest.add_tree(), [p11, p22])
     self._add_packages(forest.add_tree(), [p12, p21])
     self.assertEqual(
         p11, forest.find(generator.gen_relation("package1", [">=", 1]))
     )
     self.assertEqual(
         p12, forest.find(generator.gen_relation("package1", [">", 1]))
     )
     self.assertEqual(p22, forest.find(generator.gen_relation("package2")))
     self.assertEqual(
         p21, forest.find(generator.gen_relation("package2", ["<", 2]))
     )
Exemple #10
0
 def test_get_packages(self):
     forest = PackagesForest()
     self._generate_packages(forest)
     packages = forest.get_packages([generator.gen_relation("package3")])
     self.assertItemsEqual(["package2", "package3", "package5"],
                           (x.name for x in packages))
 def test_add_tree(self):
     forest = PackagesForest()
     tree = forest.add_tree()
     self.assertIs(tree, forest.trees[-1])