Skip to content

Commit

Permalink
Fix simplever compare handler (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Feb 1, 2021
1 parent 63a31a6 commit a4fe86d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
4 changes: 4 additions & 0 deletions awesomeversion/comparehandlers/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]:
Expand Down
27 changes: 24 additions & 3 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
57 changes: 33 additions & 24 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit a4fe86d

Please sign in to comment.