Exemplo n.º 1
0
def test_repo_name():
    p = Package("some", "1.0.0")
    assert p.full_name == "some:1.0.0"
    wrong = Package("some", "")
    assert Package.repo_name(p,
                             "/some/filename.txt") == "some/1.0.0/filename.txt"
    with pytest.raises(InvalidState):
        Package.repo_name(wrong, "/some/filename.txt")
Exemplo n.º 2
0
def test_higher(data):
    assert utils.higher([1,2], 0) == 1
    assert utils.higher([1,2], 1) == 2
    assert utils.higher([1,2], 2) == None
    assert utils.higher([1,2], 3) == None
    assert Package("hello1", "0.0.1") == utils.higher(data, Package("hello1", "0.0.0"), utils.pkg_comp_name_version)
    assert Package("hello1", "0.1.2") == utils.higher(data, Package("hello1", "0.0.3"), utils.pkg_comp_name_version)
    assert None == utils.higher(data, Package("hello2", "0.1.1"), utils.pkg_comp_name_version)
Exemplo n.º 3
0
def data():
    return [
        Package("hello1", "0.0.1"),
        Package("hello1", "0.0.2"),
        Package("hello1", "0.1.2"),
        Package("hello2", "0.1.0"),
        Package("hello2", "0.1.1"),
    ]
Exemplo n.º 4
0
def test_floor(data):
    assert utils.floor([1,2,3], 1) == 1
    assert utils.floor([1,2,3], 2) == 2
    assert utils.floor([1,2,3], 0) == None
    assert utils.floor([1,2,3], 4) == 3
    assert utils.floor([1,2,3,5], 4) == 3
    assert Package("hello1", "0.0.1") == utils.floor(data, Package("hello1", "0.0.1"), utils.pkg_comp_name_version)
    assert None == utils.floor(data, Package("hello1", "0.0.05"), utils.pkg_comp_name_version)
    assert Package("hello1", "0.0.2") == utils.lower(data, Package("hello1", "0.0.3"), utils.pkg_comp_name_version)
Exemplo n.º 5
0
def pkg_range_query(list, pkg_name, op1="", v1="", op2="", v2=""):
    from ethronsoft.gcspypi.package.package import Package
    # empty version means last version
    if op1 == "==" or not op1:
        if v1:
            x = equal(list, Package(pkg_name, complete_version(v1)),
                      pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    elif op1 == "<":
        if v1:
            x = lower(list, Package(pkg_name, complete_version(v1)),
                      pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
            x = lower(list, x, pkg_comp_name)
    elif op1 == ">":
        if v1:
            x = higher(list, Package(pkg_name, complete_version(v1)),
                       pkg_comp_name_version)
        else:
            x = None
    elif op1 == "<=":
        if v1:
            x = floor(list, Package(pkg_name, complete_version(v1)),
                      pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""),
                      pkg_comp_name)  #lower than last
    elif op1 == ">=":
        if v1:
            x = ceiling(list, Package(pkg_name, complete_version(v1)),
                        pkg_comp_name_version)
        else:
            x = lower(list, Package(pkg_name + 'x01', ""), pkg_comp_name)
    else:
        raise InvalidParameter("Invalid operator" + op1)

    if x and x.name != pkg_name:
        return None

    if v2:
        if op2 == "==":
            # return equal(list, Package(pkg_name, complete_version(v2)), pkg_comp_name_version)
            return x if x.version == complete_version(v2) else None
        elif op2 == "<":
            return x if x.version < complete_version(v2) else None
        elif op2 == ">":
            return x if x.version > complete_version(v2) else None
        elif op2 == "<=":
            return x if x.version <= complete_version(v2) else None
        elif op2 == ">=":
            return x if x.version <= complete_version(v2) else None
        else:
            raise InvalidParameter("Invalid operator" + op2)
    else:
        return x
Exemplo n.º 6
0
def items_to_package(items, unique=False):
    from ethronsoft.gcspypi.package.package import Package
    res = []
    s = set([])
    for item in items:
        tokens = item.split("/")
        name = tokens[-3]
        version = tokens[-2]
        if unique:
            key = "{}/{}".format(name, version)
            if key not in s:
                res.append(Package(name, version, type=get_package_type(item)))
                s.add(key)
        else:
            res.append(Package(name, version, type=get_package_type(item)))
    return sorted(res, key=functools.cmp_to_key(pkg_comp_name_version))
Exemplo n.º 7
0
def test_ceiling(data):
    assert utils.ceiling([1,2], 0) == 1
    assert utils.ceiling([1,2], 1) == 1
    assert utils.ceiling([1,2], 2) == 2
    assert utils.ceiling([1,2], 3) == None
    assert utils.ceiling([], -1) == None
    assert Package("hello1", "0.0.1") == utils.ceiling(data, Package("hello1", "0.0.0"), utils.pkg_comp_name_version)
    assert Package("hello1", "0.0.1") == utils.ceiling(data, Package("hello1", "0.0.1"), utils.pkg_comp_name_version)
    assert Package("hello1", "0.1.2") == utils.ceiling(data, Package("hello1", "0.0.3"), utils.pkg_comp_name_version)
    assert None == utils.ceiling(data, Package("hello3", "0.0.3"), utils.pkg_comp_name_version)
Exemplo n.º 8
0
def test_equality():
    p1 = Package("some", "1.0.0", type="A")
    p2 = Package("some", "1.0.0", type="A")
    p3 = Package("some", "1.0.0", type="B")
    p4 = Package("some", "", type="A")
    p5 = Package("other", "1.0.0", type="A")
    p6 = Package("other", "1.0.0", type="B")

    assert p1.full_name == str(p1)
    assert p1 == p2
    assert hash(p1) == hash(p2)
    assert p1 != p3
    assert hash(p1) != hash(p3)
    assert p1 != p4
    assert p2 != p5
    assert p5 != p6
Exemplo n.º 9
0
def test_from_text():
    with pytest.raises(InvalidParameter):
        Package.from_text("some>1.0.0")
    with pytest.raises(InvalidParameter):
        Package.from_text("some<1.0.0")
    with pytest.raises(InvalidParameter):
        Package.from_text("some<=1.0.0")
    with pytest.raises(InvalidParameter):
        Package.from_text("some>=1.0.0")

    assert Package.from_text("some==1.0.0") == Package("some", "1.0.0")
    assert Package.from_text("some==") == Package("some", "")
    assert Package.from_text("some") == Package("some", "")
Exemplo n.º 10
0
 def build(self):
     return Package(self.__info["name"], self.__info["version"],
                    set(self.__info["requirements"]), self.__info["type"])
Exemplo n.º 11
0
def test_range_query(data):
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", ">", "0.0.1")
    assert None == utils.pkg_range_query(data, "hello1", ">", "")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "<=", "0.0.2")
    assert Package("hello1", "0.1.2") == utils.pkg_range_query(data, "hello1", "<=", "") #last 
    assert Package("hello1", "0.1.2") == utils.pkg_range_query(data, "hello1", ">=", "") #last 
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "==", "0.0.2")
    assert Package("hello1", "0.0.1") == utils.pkg_range_query(data, "hello1", "<", "0.0.2")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "<", "") #second to last
    assert None == utils.pkg_range_query(data, "hello1", ">", "1.1.2")
    assert Package("hello1", "0.1.2") == utils.pkg_range_query(data, "hello1")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "<")

    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", ">", "0.0.1", "<=","0.0.2")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", ">", "0.0.1", "==","0.0.2")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "<", "0.1.2", ">","0.0.1")
    assert Package("hello1", "0.0.2") == utils.pkg_range_query(data, "hello1", "<", "0.1.2", ">=","0.0.2")
    assert None == utils.pkg_range_query(data, "hello1", ">", "0.0.1", "<","0.0.2")
    assert Package("hello1", "0.0.1") == utils.pkg_range_query(data, "hello1", ">=", "0.0.1", "<","0.0.2")
    assert None == utils.pkg_range_query(data, "hello1", ">", "0.0.1", "<", "0.0.1")

    with pytest.raises(InvalidParameter):
        utils.pkg_range_query(data, "hello1", "wrong-op")
    with pytest.raises(InvalidParameter):
        utils.pkg_range_query(data, "hello1", ">", "0.0.1", "wrong-op", "0.0.2")
Exemplo n.º 12
0
def test_cmp_bisect(data):
    for i in range(len(data)):
        assert i == utils.cmp_bisect(data, data[i], utils.pkg_comp_name_version)
    assert 0 == utils.cmp_bisect(data, Package("hello1", "0.0.0"), utils.pkg_comp_name_version)
    assert 2 == utils.cmp_bisect(data, Package("hello1", "0.0.3"), utils.pkg_comp_name_version)
    assert len(data) == utils.cmp_bisect(data, Package("hello3", "0.0.0"), utils.pkg_comp_name_version)