Skip to content

Commit

Permalink
chore(test): add equality and misc version range cases
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Jan 23, 2025
1 parent f717278 commit 031df6a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/poetry/core/constraints/version/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,14 @@ def is_any(self) -> bool:
def is_simple(self) -> bool:
return self._min is None or self._max is None

@property
def is_inclusive(self) -> bool:
return self._include_min or self.include_max

@property
def is_exclusive(self) -> bool:
return not self.is_inclusive

def allows(self, other: Version) -> bool:
if self._min is not None:
_this, _other = self.allowed_min, other

assert _this is not None

if (
self.is_exclusive
not self._include_min
and not _this.is_postrelease()
and _other.is_postrelease()
):
Expand Down
34 changes: 34 additions & 0 deletions tests/constraints/version/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,27 @@ def v300b1() -> Version:
@pytest.mark.parametrize(
("constraint", "check_version", "allowed"),
[
# Inclusive ordering
("<=3.0.0", "3.0.0", True),
("<=3.0.0", "3.0.0+local.1", True),
(">=3.0.0", "3.0.0", True),
(">=3.0.0", "3.0.0+local.1", True),
(">=3.0.0", "3.0.0", True),
(">=3.0.0", "3.0.0-1", True),
("<=3.0.0+local.1", "3.0.0", True),
("<=3.0.0+local.1", "3.0.0+local.1", True),
("<=3.0.0+local.1", "3.0.0+local.2", False),
("<=3.0.0+local.1", "3.0.0-1", False),
("<=3.0.0+local.1", "3.0.0-1+local.1", False),
(">=3.0.0+local.1", "3.0.0", False),
(">=3.0.0+local.1", "3.0.0+local.1", True),
(">=3.0.0+local.1", "3.0.0+local.2", True),
(">=3.0.0+local.1", "3.0.0-1", True),
(">=3.0.0+local.1", "3.0.0-1+local.1", True),
("<=3.0.0+local.2", "3.0.0+local.1", True),
("<=3.0.0+local.2", "3.0.0+local.2", True),
(">=3.0.0+local.2", "3.0.0+local.1", False),
(">=3.0.0+local.2", "3.0.0+local.2", True),
(">=3.0.0+local.2", "3.0.0-1+local.1", True),
("<=3.0.0-1", "3.0.0", True),
("<=3.0.0-1", "3.0.0+local.1", True),
Expand All @@ -113,7 +121,33 @@ def v300b1() -> Version:
(">=3.0.0-1+local.1", "3.0.0+local.2", False),
(">=3.0.0-1+local.1", "3.0.0-1", False),
("<=3.0.0-2", "3.0.0-1", True),
("<=3.0.0-2", "3.0.0-2", True),
(">=3.0.0-2", "3.0.0-1", False),
(">=3.0.0-2", "3.0.0-2", True),
# Exclusive ordering
(">1.7", "1.7.0", False),
(">1.7", "1.7.1", True),
(">1.7", "1.6.1", False),
("<1.7", "1.7.0", False),
("<1.7", "1.7.1", False),
("<1.7", "1.6.1", True),
## >V MUST NOT allow a post-release of the given version unless V itself is a post release
(">1.7", "1.7.0.post1", False),
(">1.7.post2", "1.7.0", False),
(">1.7.post2", "1.7.1", True),
(">1.7.post2", "1.7.0.post2", False),
(">1.7.post2", "1.7.0.post3", True),
## >V MUST NOT match a local version of the specified version
(">1.7.0", "1.7.0+local.1", False),
("<1.7.0", "1.7.0+local.1", False), # spec does not clarify this
("<1.7.0+local.2", "1.7.0+local.1", False), # spec does not clarify this
## <V MUST NOT allow a pre-release of the specified version unless the specified version is itself a pre-release
("<1.7.0", "1.7.0.rc1", False),
("<1.7.0.rc1", "1.7.0.rc1", False),
("<1.7.0.rc2", "1.7.0.rc1", True),
# Misc. Cases
(">=3.0.0+cuda", "3.0.0+cuda", True),
(">=3.0.0+cpu", "3.0.0+cuda", True), # cuda > cpu (lexicographically)
],
)
def test_version_ranges(constraint: str, check_version: str, allowed: bool) -> None:
Expand Down

0 comments on commit 031df6a

Please sign in to comment.