Skip to content

Commit

Permalink
fix allows_any for local versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jul 31, 2022
1 parent f9ca1eb commit c20bfd1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/poetry/core/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def allows_all(self, other: VersionConstraint) -> bool:
)

def allows_any(self, other: VersionConstraint) -> bool:
if isinstance(other, Version):
return self.allows(other)

return other.allows(self)

def intersect(self, other: VersionConstraint) -> Version | EmptyConstraint:
Expand Down
55 changes: 47 additions & 8 deletions tests/semver/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,53 @@ def test_allows_all() -> None:
assert v.allows_all(EmptyConstraint())


def test_allows_any() -> None:
v = Version.parse("1.2.3")

assert v.allows_any(v)
assert not v.allows_any(Version.parse("0.0.3"))
assert v.allows_any(VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4")))
assert v.allows_any(VersionRange())
assert not v.allows_any(EmptyConstraint())
@pytest.mark.parametrize(
("version1", "version2", "expected"),
[
(
Version.parse("1.2.3"),
Version.parse("1.2.3"),
True,
),
(
Version.parse("1.2.3"),
Version.parse("1.2.3+cpu"),
True,
),
(
Version.parse("1.2.3+cpu"),
Version.parse("1.2.3"),
False,
),
(
Version.parse("1.2.3"),
Version.parse("0.0.3"),
False,
),
(
Version.parse("1.2.3"),
VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4")),
True,
),
(
Version.parse("1.2.3"),
VersionRange(),
True,
),
(
Version.parse("1.2.3"),
EmptyConstraint(),
False,
),
],
)
def test_allows_any(
version1: VersionConstraint,
version2: VersionConstraint,
expected: bool,
) -> None:
actual = version1.allows_any(version2)
assert actual == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit c20bfd1

Please sign in to comment.