def test_allows_all(): v = Version.parse("1.2.3") assert v.allows_all(v) assert not v.allows_all(Version.parse("0.0.3")) assert not v.allows_all( VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"))) assert not v.allows_all(VersionRange()) assert v.allows_all(EmptyConstraint())
def test_intersect(): v = Version.parse("1.2.3") assert v.intersect(v) == v assert v.intersect(Version.parse("1.1.4")).is_empty() assert (v.intersect( VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"))) == v) assert (Version.parse("1.1.4").intersect( VersionRange(v, Version.parse("1.2.4"))).is_empty())
def test_difference(): v = Version.parse("1.2.3") assert v.difference(v).is_empty() assert v.difference(Version.parse("0.8.0")) == v assert v.difference( VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"))).is_empty() assert (v.difference( VersionRange(Version.parse("1.4.0"), Version.parse("3.0.0"))) == v)
def get_python_constraint_from_marker( marker, ): # type: (BaseMarker) -> VersionConstraint python_marker = marker.only("python_version") if python_marker.is_any(): return VersionRange() if python_marker.is_empty(): return EmptyConstraint() markers = convert_markers(marker) ors = [] for or_ in markers["python_version"]: ands = [] for op, version in or_: # Expand python version if op == "==": version = "~" + version op = "" elif op == "!=": version += ".*" elif op in ("<=", ">"): parsed_version = Version.parse(version) if parsed_version.precision == 1: if op == "<=": op = "<" version = parsed_version.next_major.text elif op == ">": op = ">=" version = parsed_version.next_major.text elif parsed_version.precision == 2: if op == "<=": op = "<" version = parsed_version.next_minor.text elif op == ">": op = ">=" version = parsed_version.next_minor.text elif op in ("in", "not in"): versions = [] for v in re.split("[ ,]+", version): split = v.split(".") if len(split) in [1, 2]: split.append("*") op_ = "" if op == "in" else "!=" else: op_ = "==" if op == "in" else "!=" versions.append(op_ + ".".join(split)) glue = " || " if op == "in" else ", " if versions: ands.append(glue.join(versions)) continue ands.append("{}{}".format(op, version)) ors.append(" ".join(ands)) return parse_constraint(" || ".join(ors))
def python_versions(self, value): self._python_versions = value if value == "*" or value == VersionRange(): value = "~2.7 || >=3.4" self._python_constraint = parse_constraint(value) self._python_marker = parse_marker( create_nested_marker("python_version", self._python_constraint))
def test_union(): v = Version.parse("1.2.3") assert v.union(v) == v result = v.union(Version.parse("0.8.0")) assert result.allows(v) assert result.allows(Version.parse("0.8.0")) assert not result.allows(Version.parse("1.1.4")) range = VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4")) assert v.union(range) == range union = Version.parse("1.1.4").union( VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"))) assert union == VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"), include_min=True) result = v.union( VersionRange(Version.parse("0.0.3"), Version.parse("1.1.4"))) assert result.allows(v) assert result.allows(Version.parse("0.1.0"))
def _excludes_single_version(self, constraint): # type: (Any) -> bool return isinstance(VersionRange().difference(constraint), Version)
def test_allows_all(v003, v010, v080, v114, v123, v124, v140, v200, v234, v250, v300): assert VersionRange(v123, v250).allows_all(EmptyConstraint()) range = VersionRange(v123, v250, include_max=True) assert not range.allows_all(v123) assert range.allows_all(v124) assert range.allows_all(v250) assert not range.allows_all(v300) # with no min range = VersionRange(max=v250) assert range.allows_all(VersionRange(v080, v140)) assert not range.allows_all(VersionRange(v080, v300)) assert range.allows_all(VersionRange(max=v140)) assert not range.allows_all(VersionRange(max=v300)) assert range.allows_all(range) assert not range.allows_all(VersionRange()) # with no max range = VersionRange(min=v010) assert range.allows_all(VersionRange(v080, v140)) assert not range.allows_all(VersionRange(v003, v140)) assert range.allows_all(VersionRange(v080)) assert not range.allows_all(VersionRange(v003)) assert range.allows_all(range) assert not range.allows_all(VersionRange()) # Allows bordering range that is not more inclusive exclusive = VersionRange(v010, v250) inclusive = VersionRange(v010, v250, True, True) assert inclusive.allows_all(exclusive) assert inclusive.allows_all(inclusive) assert not exclusive.allows_all(inclusive) assert exclusive.allows_all(exclusive) # Allows unions that are completely contained range = VersionRange(v114, v200) assert range.allows_all(VersionRange(v123, v124).union(v140)) assert not range.allows_all(VersionRange(v010, v124).union(v140)) assert not range.allows_all(VersionRange(v123, v234).union(v140))
def test_include_max_prerelease(v200, v300, v300b1): result = VersionRange(v200, v300) assert not result.allows(v300b1) assert not result.allows_any(VersionRange(v300b1)) assert not result.allows_all(VersionRange(v200, v300b1)) result = VersionRange(v200, v300, always_include_max_prerelease=True) assert result.allows(v300b1) assert result.allows_any(VersionRange(v300b1)) assert result.allows_all(VersionRange(v200, v300b1))
def test_union(v003, v010, v072, v080, v114, v123, v124, v130, v140, v200, v234, v250, v300): # with a version returns the range if it contains the version range = VersionRange(v114, v124) assert range.union(v123) == range # with a version on the edge of the range, expands the range range = VersionRange(v114, v124) assert range.union(v124) == VersionRange(v114, v124, include_max=True) assert range.union(v114) == VersionRange(v114, v124, include_min=True) # with a version allows both the range and the version if the range # doesn't contain the version result = VersionRange(v003, v114).union(v124) assert result.allows(v010) assert not result.allows(v123) assert result.allows(v124) # returns a VersionUnion for a disjoint range result = VersionRange(v003, v114).union(VersionRange(v130, v200)) assert result.allows(v080) assert not result.allows(v123) assert result.allows(v140) # considers open ranges disjoint result = VersionRange(v003, v114).union(VersionRange(v114, v200)) assert result.allows(v080) assert not result.allows(v114) assert result.allows(v140) result = VersionRange(v114, v200).union(VersionRange(v003, v114)) assert result.allows(v080) assert not result.allows(v114) assert result.allows(v140) # returns a merged range for an overlapping range result = VersionRange(v003, v114).union(VersionRange(v080, v200)) assert result == VersionRange(v003, v200) # considers closed ranges overlapping result = VersionRange(v003, v114, include_max=True).union(VersionRange(v114, v200)) assert result == VersionRange(v003, v200) result = VersionRange(v003, v114).union( VersionRange(v114, v200, include_min=True)) assert result == VersionRange(v003, v200)
def test_intersect(v114, v123, v124, v200, v250, v300): # two overlapping ranges assert VersionRange(v123, v250).intersect(VersionRange( v200, v300)) == VersionRange(v200, v250) # a non-overlapping range allows no versions a = VersionRange(v114, v124) b = VersionRange(v200, v250) assert a.intersect(b).is_empty() # adjacent ranges allow no versions if exclusive a = VersionRange(v114, v124) b = VersionRange(v124, v200) assert a.intersect(b).is_empty() # adjacent ranges allow version if inclusive a = VersionRange(v114, v124, include_max=True) b = VersionRange(v124, v200, include_min=True) assert a.intersect(b) == v124 # with an open range open = VersionRange() a = VersionRange(v114, v124) assert open.intersect(open) == open assert open.intersect(a) == a # returns the version if the range allows it assert VersionRange(v114, v124).intersect(v123) == v123 assert VersionRange(v123, v124).intersect(v114).is_empty()
def test_allows_any(v003, v010, v072, v080, v114, v123, v124, v140, v200, v234, v250, v300): # disallows an empty constraint assert not VersionRange(v123, v250).allows_any(EmptyConstraint()) # allows allowed versions range = VersionRange(v123, v250, include_max=True) assert not range.allows_any(v123) assert range.allows_any(v124) assert range.allows_any(v250) assert not range.allows_any(v300) # with no min range = VersionRange(max=v200) assert range.allows_any(VersionRange(v140, v300)) assert not range.allows_any(VersionRange(v234, v300)) assert range.allows_any(VersionRange(v140)) assert not range.allows_any(VersionRange(v234)) assert range.allows_any(range) # with no max range = VersionRange(min=v072) assert range.allows_any(VersionRange(v003, v140)) assert not range.allows_any(VersionRange(v003, v010)) assert range.allows_any(VersionRange(max=v080)) assert not range.allows_any(VersionRange(max=v003)) assert range.allows_any(range) # with min and max range = VersionRange(v072, v200) assert range.allows_any(VersionRange(v003, v140)) assert range.allows_any(VersionRange(v140, v300)) assert not range.allows_any(VersionRange(v003, v010)) assert not range.allows_any(VersionRange(v234, v300)) assert not range.allows_any(VersionRange(max=v010)) assert not range.allows_any(VersionRange(v234)) assert range.allows_any(range) # allows a bordering range when both are inclusive assert not VersionRange(max=v250).allows_any(VersionRange(min=v250)) assert not VersionRange(max=v250, include_max=True).allows_any( VersionRange(min=v250)) assert not VersionRange(max=v250).allows_any( VersionRange(min=v250, include_min=True)) assert not VersionRange(min=v250).allows_any(VersionRange(max=v250)) assert VersionRange(max=v250, include_max=True).allows_any( VersionRange(min=v250, include_min=True)) # allows unions that are partially contained' range = VersionRange(v114, v200) assert range.allows_any(VersionRange(v010, v080).union(v140)) assert range.allows_any(VersionRange(v123, v234).union(v300)) assert not range.allows_any(VersionRange(v234, v300).union(v010)) # pre-release min does not allow lesser than itself range = VersionRange(Version.parse("1.9b1"), include_min=True) assert not range.allows_any( VersionRange( Version.parse("1.8.0"), Version.parse("1.9.0"), include_min=True))
def test_parse_constraint_multi_wilcard(input): assert parse_constraint(input) == VersionUnion( VersionRange(Version(2, 7, 0), Version(3, 0, 0), True, False), VersionRange(Version(3, 2, 0), None, True, False), )
def test_parse_constraint_multi(input): assert parse_constraint(input) == VersionRange( Version(2, 0, 0), Version(3, 0, 0), include_min=False, include_max=True )
import pytest from poetry.core.semver import Version from poetry.core.semver import VersionRange from poetry.core.semver import VersionUnion from poetry.core.semver import parse_constraint @pytest.mark.parametrize( "input,constraint", [ ("*", VersionRange()), ("*.*", VersionRange()), ("v*.*", VersionRange()), ("*.x.*", VersionRange()), ("x.X.x.*", VersionRange()), # ('!=1.0.0', Constraint('!=', '1.0.0.0')), (">1.0.0", VersionRange(min=Version(1, 0, 0))), ("<1.2.3", VersionRange(max=Version(1, 2, 3))), ("<=1.2.3", VersionRange(max=Version(1, 2, 3), include_max=True)), (">=1.2.3", VersionRange(min=Version(1, 2, 3), include_min=True)), ("=1.2.3", Version(1, 2, 3)), ("1.2.3", Version(1, 2, 3)), ("=1.0", Version(1, 0, 0)), ("1.2.3b5", Version(1, 2, 3, pre="b5")), (">= 1.2.3", VersionRange(min=Version(1, 2, 3), include_min=True)), (">dev", VersionRange(min=Version(0, 0, pre="dev"))), # Issue 206 ], ) def test_parse_constraint(input, constraint): assert parse_constraint(input) == constraint
import pytest from poetry.core.semver import Version from poetry.core.semver import VersionRange from poetry.core.semver import VersionUnion from poetry.core.semver import parse_constraint @pytest.mark.parametrize( "constraint,version", [ ("~=3.8", VersionRange(min=Version(3, 8), max=Version(4, 0), include_min=True)), ( "== 3.8.*", VersionRange( min=Version(3, 8), max=Version(3, 9, 0), include_min=True), ), ( "~= 3.8", VersionRange( min=Version(3, 8), max=Version(4, 0), include_min=True), ), ("~3.8", VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True)), ("~ 3.8", VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True)), (">3.8", VersionRange(min=Version(3, 8))), (">=3.8", VersionRange(min=Version(3, 8), include_min=True)), (">= 3.8", VersionRange(min=Version(3, 8), include_min=True)), (