From a4fe86d4e2d8e96f85b8f93930c2a597e03146ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 1 Feb 2021 15:30:11 +0100 Subject: [PATCH] Fix simplever compare handler (#41) --- awesomeversion/comparehandlers/simple.py | 4 ++ tests/test_compare.py | 27 +++++++++-- tests/test_handlers.py | 57 ++++++++++++++---------- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/awesomeversion/comparehandlers/simple.py b/awesomeversion/comparehandlers/simple.py index 96fc40d..ff28b74 100644 --- a/awesomeversion/comparehandlers/simple.py +++ b/awesomeversion/comparehandlers/simple.py @@ -11,6 +11,10 @@ class ComparelHandlerSimple(ComparelHandlerSections): def handler(self) -> Optional[bool]: """Compare handler.""" + if self.ver_a.simple and self.ver_b.simple: + if self._compare_base_sections(self.ver_a, self.ver_b) is None: + return False + if self.ver_a.simple and self.ver_b.strategy not in [ AwesomeVersionStrategy.SPECIALCONTAINER ]: diff --git a/tests/test_compare.py b/tests/test_compare.py index 26451d9..b8b8880 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -16,6 +16,8 @@ ("2", 1), (2, "1"), (2, 1), + ("5.11", "5.10"), + ("1.1", "1.0"), ("2020", "2019"), ("1.2.3.4", "1.2.3"), ("2020.1", "2020"), @@ -51,16 +53,13 @@ def test_compare(version_a, version_b): ver_a = AwesomeVersion(version_a) ver_b = AwesomeVersion(version_b) - assert ver_a > ver_b assert ver_a > ver_b assert ver_a >= ver_b assert ver_a != ver_b assert ver_a > version_b - assert ver_a > version_b assert ver_a >= version_b assert ver_a != version_b assert version_a > ver_b - assert version_a > ver_b assert version_a >= ver_b assert version_a != ver_b assert ver_b < ver_a @@ -100,3 +99,25 @@ def test_invalid_compare(): with pytest.raises(AwesomeVersionCompare, match="Can't compare unknown"): assert AwesomeVersion("2020.12.1") < AwesomeVersion("string") + + +@pytest.mark.parametrize( + "version", + [1, "1", 1.0, "1.0", 5.10, "5.10"], +) +def test_falsy_compare(version): + """Test compare.""" + ver_a = AwesomeVersion(version) + ver_b = AwesomeVersion(version) + + assert not ver_a != ver_b + assert not ver_a > ver_b + assert not ver_a < ver_b + + assert not version != ver_b + assert not version > ver_b + assert not version < ver_b + + assert not ver_a != version + assert not ver_a > version + assert not ver_a < version diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 0a6cd26..6500ca8 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -4,46 +4,55 @@ def test_container(): - handlers = CompareHandlers(AwesomeVersion("latest"), AwesomeVersion("stable")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("latest"), AwesomeVersion("stable")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("latest"), AwesomeVersion("1")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("latest"), AwesomeVersion("1")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("1.0.0"), AwesomeVersion("stable")) - assert not handlers.check() + handler = CompareHandlers(AwesomeVersion("1.0.0"), AwesomeVersion("stable")) + assert not handler.check() def test_dev(): - handlers = CompareHandlers(AwesomeVersion("1.dev1"), AwesomeVersion("1.dev0")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("1.dev1"), AwesomeVersion("1.dev0")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("1.dev0"), AwesomeVersion("1.dev1")) - assert not handlers.check() + handler = CompareHandlers(AwesomeVersion("1.dev0"), AwesomeVersion("1.dev1")) + assert not handler.check() def test_modifier(): - handlers = CompareHandlers(AwesomeVersion("1.0b1"), AwesomeVersion("1.0b0")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("1.0b1"), AwesomeVersion("1.0b0")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("1.0"), AwesomeVersion("1.0b0")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("1.0"), AwesomeVersion("1.0b0")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("1.0b0"), AwesomeVersion("1.0b1")) - assert not handlers.check() + handler = CompareHandlers(AwesomeVersion("1.0b0"), AwesomeVersion("1.0b1")) + assert not handler.check() - handlers = CompareHandlers(AwesomeVersion("1.0b0"), AwesomeVersion("1.0")) - assert not handlers.check() + handler = CompareHandlers(AwesomeVersion("1.0b0"), AwesomeVersion("1.0")) + assert not handler.check() def test_sectons(): - handlers = CompareHandlers(AwesomeVersion("1.2.3.4.5b0"), AwesomeVersion("1.2b0")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("1.2.3.4.5b0"), AwesomeVersion("1.2b0")) + assert handler.check() def test_simple(): - handlers = CompareHandlers(AwesomeVersion("2"), AwesomeVersion("1")) - assert handlers.check() + handler = CompareHandlers(AwesomeVersion("2"), AwesomeVersion("1")) + assert handler.check() - handlers = CompareHandlers(AwesomeVersion("1"), AwesomeVersion("2")) - assert not handlers.check() + handler = CompareHandlers(AwesomeVersion("1"), AwesomeVersion("2")) + assert not handler.check() + + handler = CompareHandlers(AwesomeVersion("1"), AwesomeVersion("1")) + assert not handler.check() + + handler = CompareHandlers(AwesomeVersion("1.0"), AwesomeVersion("1.0")) + assert not handler.check() + + handler = CompareHandlers(AwesomeVersion("5.10"), AwesomeVersion("5.10")) + assert not handler.check()