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/cpe/test_cpe.py b/tests/cpe/test_cpe.py index aae9d9d65..6eef4454a 100644 --- a/tests/cpe/test_cpe.py +++ b/tests/cpe/test_cpe.py @@ -245,7 +245,6 @@ def test_formatted_string_binding(self): "cpe:2.3:a:qrokes:qr_twitter_widget:*:*:*:*:*:wordpress:*:*" ) cpe = CPE.from_string(cpe_string) - print(repr(cpe)) self.assertEqual( str(cpe), @@ -403,7 +402,6 @@ def test_uri_unbind_examples(self): cpe = CPE.from_string( "cpe:/a:hp:insight_diagnostics:7.4.0.1570::~~online~win2003~x64~" ) - print(repr(cpe)) self.assertTrue(cpe.is_uri_binding()) self.assertFalse(cpe.is_formatted_string_binding()) self.assertEqual(cpe.part, Part.APPLICATION) 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",