Пример #1
0
    def validate(self):
        version = self.version
        if version:
            version = VersionReq.parse(self.version)
        if self.revision and self.version:
            raise ValueError(
                'Dependency cannot specify `commit` and `version` at the same time.'
            )
        if self.path and self.url:
            raise ValueError(
                'Dependency cannot specify `path` and `url` at the same time.')
        git_url = self.path if self.path else self.url

        if self.path:
            git_url = self.path
            is_local = True
        else:
            git_url = self.url
            is_local = False

        if self.revision:
            rev_ver = self.revision
            use_version = False
        else:
            rev_ver = version
            use_version = True

        return Dependency(git_url, rev_ver, use_version, is_local)
Пример #2
0
    def validate(self):
        if not isinstance(self.val, (VersionReq, str)):
            msg = '"{}" must be a semver version request string'.format(
                self.val)
            raise ValidatorError(self.chain_keys_str(), msg)

        if type(self.val) == VersionReq:
            return self.val

        try:
            VersionReq.parse(self.val)
        except Exception:
            fmt = '{} is not a valid semver version request string'
            msg = fmt.format(self.val)
            raise ValidatorError(self.chain_keys_str(), msg) from None

        return self.val
Пример #3
0
def test_from_str():
    assert str(VersionReq.parse("1.0.0")) == "^1.0.0"
    assert str(VersionReq.parse("=1.0.0")) == "= 1.0.0"
    assert str(VersionReq.parse("~1")) == "~1"
    assert str(VersionReq.parse("~1.2")) == "~1.2"
    assert str(VersionReq.parse("^1")) == "^1"
    assert str(VersionReq.parse("^1.1")) == "^1.1"
    assert str(VersionReq.parse("< 1.0.0")) == "< 1.0.0"
Пример #4
0
def test_parsing_less_failed_case1():
    with pytest.raises(ValueError) as excinfo:
        VersionReq.parse("> 0.3.0, ,")
    assert excinfo.type == ValueError
Пример #5
0
def assert_not_match(req: VersionReq, vers: typing.Iterable[str]):
    for ver in vers:
        assert not req.matches(version(ver)), "matched {}".format(ver)
Пример #6
0
def test_any():
    r = VersionReq.any()
    assert_match(r, ["0.0.1", "0.1.0", "1.0.0"])
Пример #7
0
def assert_match(req: VersionReq, vers: typing.Iterable[str]):
    for ver in vers:
        assert req.matches(version(ver)), "didn't match {}".format(ver)
Пример #8
0
def req(s: str):
    return VersionReq.parse(s)