Exemplo n.º 1
0
def _cli_format_semver(version, type_):
    def _format(x):
        return cli_format(x, cli.YELLOW)

    try:
        semver.parse(version)

        if type_ == "major":
            version = _format(version)
        if type_ == "minor":
            index = version.find(".", 1) + 1
            head, tail = version[:index], version[index:]
            version = "".join([head, _format(tail)])
        if type_ == "patch":
            index = version.find(".", 2) + 1
            head, tail = version[:index], version[index:]
            version = "".join([head, _format(tail)])
    except ValueError:
        pass

    return version
Exemplo n.º 2
0
def test_parse():
    version = parse("1.2.3")
    assert version["major"] == 1
    assert version["minor"] == 2
    assert version["patch"] == 3
    assert not version["prerelease"]
    assert not version["build"]

    version = parse("1.2.3-develop+1234")
    assert version["major"] == 1
    assert version["minor"] == 2
    assert version["patch"] == 3
    assert version["prerelease"] == "develop"
    assert version["build"] == "1234"

    with pytest.raises(ValueError):
        parse("foobar")

    with pytest.raises(ValueError):
        parse("1.0")
Exemplo n.º 3
0
def test__get_package_version():
    version = _get_package_version("pipupgrade")
    semver.parse(version)