From 863f54af6089168dfa9d563a76c0a149dfa06f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 8 Nov 2023 11:44:32 +0100 Subject: [PATCH] Add: Add additional comparison for Version classes (ge, lt and le) Allow to compare versions with greater or equal then, less then and less or equal then. This is required for comparing CPE versions. --- pontos/version/schemes/_pep440.py | 21 +++ pontos/version/schemes/_semantic.py | 36 ++-- pontos/version/version.py | 12 ++ tests/version/schemes/test_pep440.py | 234 ++++++++++++++++++++++++ tests/version/schemes/test_semantic.py | 237 +++++++++++++++++++++++++ 5 files changed, 526 insertions(+), 14 deletions(-) diff --git a/pontos/version/schemes/_pep440.py b/pontos/version/schemes/_pep440.py index 0b61c076b..36e1331d1 100644 --- a/pontos/version/schemes/_pep440.py +++ b/pontos/version/schemes/_pep440.py @@ -225,6 +225,27 @@ def __gt__(self, other: Any) -> bool: other = self.from_version(other) return self._version > other._version + def __ge__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return self._version >= other._version + + def __lt__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return self._version < other._version + + def __le__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return self._version <= other._version + def __str__(self) -> str: return str(self._version) diff --git a/pontos/version/schemes/_semantic.py b/pontos/version/schemes/_semantic.py index 666cc1d71..4b2690cca 100644 --- a/pontos/version/schemes/_semantic.py +++ b/pontos/version/schemes/_semantic.py @@ -164,20 +164,7 @@ def __eq__(self, other: Any) -> bool: ) def __ne__(self, other: Any) -> bool: - if other is None: - return True - if isinstance(other, str): - # allow to compare against "current" for now - return True - if not isinstance(other, Version): - raise ValueError(f"Can't compare {type(self)} with {type(other)}") - if not isinstance(other, type(self)): - other = self.from_version(other) - - return ( - self._version_info != other._version_info - or self._version_info.build != other._version_info.build - ) + return not self == other def __gt__(self, other: Any) -> bool: if not isinstance(other, Version): @@ -223,6 +210,27 @@ def __gt__(self, other: Any) -> bool: # both are equal return False + def __ge__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return self > other or self == other + + def __lt__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return (not self > other) and self != other + + def __le__(self, other: Any) -> bool: + if not isinstance(other, Version): + raise ValueError(f"Can't compare {type(self)} with {type(other)}") + if not isinstance(other, type(self)): + other = self.from_version(other) + return not self > other or self == other + def __str__(self) -> str: """A string representation of the version""" return str(self._version_info) diff --git a/pontos/version/version.py b/pontos/version/version.py index cac7caf2b..d6cfbf0c9 100644 --- a/pontos/version/version.py +++ b/pontos/version/version.py @@ -146,6 +146,18 @@ def __ne__(self, other: Any) -> bool: def __gt__(self, other: Any) -> bool: pass + @abstractmethod + def __ge__(self, other: Any) -> bool: + pass + + @abstractmethod + def __lt__(self, other: Any) -> bool: + pass + + @abstractmethod + def __le__(self, other: Any) -> bool: + pass + @abstractmethod def __str__(self) -> str: """A string representation of the version""" diff --git a/tests/version/schemes/test_pep440.py b/tests/version/schemes/test_pep440.py index d75c2eb42..b12f27769 100644 --- a/tests/version/schemes/test_pep440.py +++ b/tests/version/schemes/test_pep440.py @@ -336,6 +336,240 @@ def test_greater_then(self): f"{version1} should not be greater then {version2}", ) + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) > version2) + + def test_greater_or_equal_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0"), + ("1.0.0", "1.0.0.dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0.dev1", "1.0.0.dev1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1.dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1", "1.0.0-beta1.dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev1"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1.dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + ] + for version1, version2 in versions: + self.assertTrue( + Version.from_string(version1) >= Version.from_string(version2), + f"{version1} should be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0", "1.0.0+dev1"), + ("1.0.0.dev1", "1.0.0.dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev2"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev2"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev2"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version1, version2 in versions: + self.assertFalse( + Version.from_string(version1) >= Version.from_string(version2), + f"{version1} should not be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) >= version2) + + def test_less_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0.dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1.dev1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1.dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1.dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + ] + for version2, version1 in versions: + self.assertTrue( + Version.from_string(version1) < Version.from_string(version2), + f"{version1} should be less then {version2}", + ) + + versions = [ + ("1.0.0", "1.0.0"), + ("1.0.0", "1.0.0+dev1"), + ("1.0.0.dev1", "1.0.0.dev1"), + ("1.0.0.dev1", "1.0.0.dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev2"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev2"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev2"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version2, version1 in versions: + self.assertFalse( + Version.from_string(version1) < Version.from_string(version2), + f"{version1} should not be less then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) < version2) + + def test_less_or_equal_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0"), + ("1.0.0", "1.0.0.dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0.dev1", "1.0.0.dev1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1.dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1", "1.0.0-beta1.dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev1"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1.dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + ] + for version2, version1 in versions: + self.assertTrue( + Version.from_string(version1) <= Version.from_string(version2), + f"{version1} should be less or equal then {version2}", + ) + + versions = [ + ("1.0.0", "1.0.0+dev1"), + ("1.0.0.dev1", "1.0.0.dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0-alpha1.dev1", "1.0.0-alpha1.dev2"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1.dev1", "1.0.0-beta1.dev2"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1.dev1", "1.0.0-rc1.dev2"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version2, version1 in versions: + self.assertFalse( + Version.from_string(version1) <= Version.from_string(version2), + f"{version1} should not be less or equal then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) <= version2) + def test_is_dev_release(self): versions = [ "1.0.0.dev1", diff --git a/tests/version/schemes/test_semantic.py b/tests/version/schemes/test_semantic.py index 2bed01d7d..ef0c76922 100644 --- a/tests/version/schemes/test_semantic.py +++ b/tests/version/schemes/test_semantic.py @@ -306,6 +306,243 @@ def test_greater_then(self): f"{version1} should not be greater then {version2}", ) + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) > version2) + + def test_greater_or_equal_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.0", "1.0.0"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0-dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0-dev1", "1.0.0-dev1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1", "1.0.0-beta1-dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1", "1.0.0-rc1-dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev1"), + ] + for version1, version2 in versions: + self.assertTrue( + Version.from_string(version1) >= Version.from_string(version2), + f"{version1} should be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0", "1.0.0+dev1"), + ("1.0.0-dev1", "1.0.0-dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev2"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev2"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev2"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version1, version2 in versions: + self.assertFalse( + Version.from_string(version1) >= Version.from_string(version2), + f"{version1} should not be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) >= version2) + + def test_less_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0-dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1-dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1-dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + # the following ones are strange with current semver implementation + # because they are both less then and greater then at the same time + ("1.0.0", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version2, version1 in versions: + self.assertTrue( + Version.from_string(version1) < Version.from_string(version2), + f"{version1} should be less then {version2}", + ) + + versions = [ + ("1.0.0", "1.0.0"), + ("1.0.0-dev1", "1.0.0-dev1"), + ("1.0.0-dev1", "1.0.0-dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev1"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev2"), + ] + for version2, version1 in versions: + self.assertFalse( + Version.from_string(version1) < Version.from_string(version2), + f"{version1} should not be less then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) < version2) + + def test_less_or_equal_then(self): + versions = [ + ("1.0.0", "0.9.9999"), + ("1.0.0", "1.0.0"), + ("1.0.1", "1.0.0"), + ("1.0.0", "1.0.0-dev1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-alpha1"), + ("1.0.0", "1.0.0-beta1"), + ("1.0.0", "1.0.0-rc1"), + ("1.0.0-dev1", "1.0.0-dev1"), + ("1.0.0+dev1", "1.0.0+dev1"), + ("1.0.0-alpha1", "1.0.0-dev1"), + ("1.0.0-alpha1", "1.0.0-alpha1"), + ("1.0.0-alpha1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev1"), + ("1.0.0-alpha2", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-dev1"), + ("1.0.0-beta1", "1.0.0-alpha1"), + ("1.0.0-beta1", "1.0.0-beta1"), + ("1.0.0-beta1", "1.0.0-beta1-dev1"), + ("1.0.0-beta2", "1.0.0-beta1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev1"), + ("1.0.0-rc1", "1.0.0-dev1"), + ("1.0.0-rc1", "1.0.0-alpha1"), + ("1.0.0-rc1", "1.0.0-beta1"), + ("1.0.0-rc1", "1.0.0-rc1"), + ("1.0.0-rc1", "1.0.0-rc1-dev1"), + ("1.0.0-rc2", "1.0.0-rc1"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev1"), + # the strange ones + ("1.0.0", "1.0.0+dev1"), + ("1.0.0+dev1", "1.0.0+dev2"), + ("1.0.0-alpha1", "1.0.0-alpha1+dev1"), + ("1.0.0-alpha1+dev1", "1.0.0-alpha1+dev2"), + ("1.0.0-beta1", "1.0.0-beta1+dev1"), + ("1.0.0-beta1+dev1", "1.0.0-beta1+dev2"), + ("1.0.0-rc1", "1.0.0-rc1+dev1"), + ("1.0.0-rc1+dev1", "1.0.0-rc1+dev2"), + ] + for version2, version1 in versions: + self.assertTrue( + Version.from_string(version1) <= Version.from_string(version2), + f"{version1} should be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0-dev1", "1.0.0-dev2"), + ("1.0.0", "1.0.1"), + ("1.0.0-dev1", "1.0.0"), + ("1.0.0-dev1", "1.0.0-alpha1"), + ("1.0.0-dev1", "1.0.0-beta1"), + ("1.0.0-dev1", "1.0.0-rc1"), + ("1.0.0-alpha1", "1.0.0-beta1"), + ("1.0.0-alpha1", "1.0.0-rc1"), + ("1.0.0-alpha1-dev1", "1.0.0-alpha1-dev2"), + ("1.0.0-beta1", "1.0.0-rc1"), + ("1.0.0-beta1-dev1", "1.0.0-beta1-dev2"), + ("1.0.0-rc1", "1.0.0"), + ("1.0.0-rc1-dev1", "1.0.0-rc1-dev2"), + ] + for version2, version1 in versions: + self.assertFalse( + Version.from_string(version1) <= Version.from_string(version2), + f"{version1} should not be greater or equal then {version2}", + ) + + versions = [ + ("1.0.0", object()), + ("1.0.0", 1), + ("1.0.0", True), + ] + for version1, version2 in versions: + with self.assertRaisesRegex(ValueError, "Can't compare"): + self.assertFalse(Version.from_string(version1) <= version2) + def test_is_dev_release(self): versions = [ "1.0.0-dev1",