Skip to content

Commit

Permalink
🧪 Add test for VersionLike comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelWO committed Jan 3, 2025
1 parent 4f8d4f1 commit 646d0c6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

import pytest

from pirel._utils import VersionLike


@pytest.mark.parametrize(
"a, b, cmp, expected",
[
[(3, 8), (3, 7, 6), "==", False],
[(3, 8), (3, 7, 6), "<", False],
[(3, 8), (3, 7, 6), "<=", False],
[(3, 8), (3, 7, 6), ">", True],
[(3, 8), (3, 7, 6), ">=", True],
],
)
def test_version_comparison(a, b, cmp, expected):
class AVersion(VersionLike):
@property
def version_tuple(self) -> tuple[int, ...]:
return a

class BVersion(VersionLike):
@property
def version_tuple(self) -> tuple[int, ...]:
return b

obj_a = AVersion()
obj_b = BVersion()
assert eval(f"obj_a {cmp} obj_b", {"obj_a": obj_a, "obj_b": obj_b}) == expected

0 comments on commit 646d0c6

Please sign in to comment.