def test_find_package(self):
        tree = PackagesTree()
        p1 = generator.gen_package(idx=1, version=1)
        p2 = generator.gen_package(idx=1, version=2)
        tree.add(p1)
        tree.add(p2)

        self.assertIs(p1, tree.find(p1.name, VersionRange("<", p2.version)))
        self.assertIs(p2, tree.find(p1.name, VersionRange(">=", p1.version)))
        self.assertIsNone(tree.find(p1.name, VersionRange(">", p2.version)))
예제 #2
0
 def test_from_args(self):
     r = PackageRelation.from_args(("test", "<=", 2), ("test2", ),
                                   ("test3", ))
     self.assertEqual("test", r.name)
     self.assertEqual("<=", r.version.op)
     self.assertEqual(2, r.version.edge)
     self.assertEqual("test2", r.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.version)
     self.assertEqual("test3", r.alternative.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.alternative.version)
     self.assertIsNone(r.alternative.alternative.alternative)
    def test_find_provides(self):
        tree = PackagesTree()
        p1 = generator.gen_package(
            version=1, obsoletes=[generator.gen_relation('provide', ('<', 2))]
        )
        tree.add(p1)

        self.assertIs(
            p1, tree.find("provide", VersionRange("<=", 2))
        )
        self.assertIsNone(
            tree.find("provide", VersionRange(">", 2))
        )
    def test_find_obsolete(self):
        tree = PackagesTree()
        p1 = generator.gen_package(
            version=1, obsoletes=[generator.gen_relation('obsolete', ('<', 2))]
        )
        p2 = generator.gen_package(
            version=2, obsoletes=[generator.gen_relation('obsolete', ('<', 2))]
        )
        tree.add(p1)
        tree.add(p2)

        self.assertEqual(
            [p1, p2], tree.find_all("obsolete", VersionRange("<=", 2))
        )
        self.assertIsNone(
            tree.find("obsolete", VersionRange(">", 2))
        )
예제 #5
0
    def _parse_package_relations(relations):
        """Parses yum package relations.

        :param relations: list of tuples
                          (name, flags, (epoch, version, release))
        :return: list of PackageRelation objects
        """
        return [
            PackageRelation(
                x[0],
                VersionRange(_OPERATORS_MAPPING[x[1]], x[1]
                             and RpmPackageVersion(*x[2]))) for x in relations
        ]
 def test_add(self):
     tree = PackagesTree()
     pkg = generator.gen_package(version=1, mandatory=True)
     tree.add(pkg)
     self.assertIs(pkg, tree.find(pkg.name, VersionRange('=', pkg.version)))
     self.assertIs(
         pkg.obsoletes[0],
         tree.obsoletes[pkg.obsoletes[0].name][(pkg.name, pkg.version)]
     )
     self.assertIs(
         pkg.provides[0],
         tree.provides[pkg.provides[0].name][(pkg.name, pkg.version)]
     )
     tree.add(generator.gen_package(version=1, mandatory=False))
     self.assertItemsEqual([pkg], tree.mandatory_packages)
예제 #7
0
 def __check_intersection(self, assertion, cases):
     for data in cases:
         v1 = VersionRange(*data[0])
         v2 = VersionRange(*data[1])
         assertion(
             v1.has_intersection(v2), msg="%s and %s" % (v1, v2)
         )
         assertion(
             v2.has_intersection(v1), msg="%s and %s" % (v2, v1)
         )
예제 #8
0
 def test_intersection_is_typesafe(self):
     with self.assertRaises(TypeError):
         VersionRange("=", 1).has_intersection(("=", 1))
예제 #9
0
 def test_hashable(self):
     self.check_hashable(
         VersionRange(op="<="),
         VersionRange(op="<=", edge=3)
     )
예제 #10
0
 def test_equal(self):
     self.check_equal(
         VersionRange("=", 1),
         VersionRange("=", 1),
         VersionRange("<=", 1)
     )