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)
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
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"
def test_parsing_less_failed_case1(): with pytest.raises(ValueError) as excinfo: VersionReq.parse("> 0.3.0, ,") assert excinfo.type == ValueError
def req(s: str): return VersionReq.parse(s)