Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix allows_any for local versions #433

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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