def test_find_down_up(self):
     index = Index()
     p1 = gen_package(version=1)
     p2 = gen_package(version=2)
     index.add(p1)
     index.add(p2)
     self.assertEqual([p2],
                      index.find_all(p1.name, objects.VersionRange(">=",
                                                                   2)))
     self.assertEqual([p2],
                      index.find_all(p1.name, objects.VersionRange(">", 1)))
     self.assertEqual([],
                      index.find_all(p1.name, objects.VersionRange(">", 2)))
    def test_find_with_specified_version(self):
        index = Index()
        p1 = gen_package(idx=1, version=1)
        p2 = gen_package(idx=1, version=2)
        index.add(p1)
        index.add(p2)

        self.assertItemsEqual([p1],
                              index.find_all(
                                  p1.name,
                                  objects.VersionRange("=", p1.version)))
        self.assertItemsEqual([p2],
                              index.find_all(
                                  p2.name,
                                  objects.VersionRange("=", p2.version)))
def gen_relation(name="test", version=None, alternative=None):
    """Helper to create PackageRelation object with default attributes."""
    return objects.PackageRelation(
        name=name,
        version=objects.VersionRange(*(version or [])),
        alternative=alternative)