From 3dec94dc859b2288e3d55603b1c1e79f5290e0cd Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Thu, 3 Nov 2022 21:40:20 +0100 Subject: [PATCH] add more tests for version comparisons and reformat with black --- rust2rpm/core/metadata.py | 10 ++-------- rust2rpm/tests/test_version.py | 4 ++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/rust2rpm/core/metadata.py b/rust2rpm/core/metadata.py index 7f2bb1f..4ec0895 100644 --- a/rust2rpm/core/metadata.py +++ b/rust2rpm/core/metadata.py @@ -165,10 +165,7 @@ class CargoSemVer: or (v1.major == v2.major and v1.minor == v2.minor and v1.patch > v2.patch) ) elif op == CargoSemVer.KIND_GTE: - return ( - CargoSemVer.eval_(v1, CargoSemVer.KIND_GT, v2) - or CargoSemVer.eval_(v1, CargoSemVer.KIND_SHORTEQ, v2) - ) + return CargoSemVer.eval_(v1, CargoSemVer.KIND_GT, v2) or CargoSemVer.eval_(v1, CargoSemVer.KIND_SHORTEQ, v2) elif op == CargoSemVer.KIND_LT: return ( (v1.major < v2.major) @@ -176,10 +173,7 @@ class CargoSemVer: or (v1.major == v2.major and v1.minor == v2.minor and v1.patch < v2.patch) ) elif op == CargoSemVer.KIND_LTE: - return ( - CargoSemVer.eval_(v1, CargoSemVer.KIND_LT, v2) - or CargoSemVer.eval_(v1, CargoSemVer.KIND_SHORTEQ, v2) - ) + return CargoSemVer.eval_(v1, CargoSemVer.KIND_LT, v2) or CargoSemVer.eval_(v1, CargoSemVer.KIND_SHORTEQ, v2) else: raise ValueError(f"Cannot evaluate operator: {op}") diff --git a/rust2rpm/tests/test_version.py b/rust2rpm/tests/test_version.py index 746d9e0..4a338c0 100644 --- a/rust2rpm/tests/test_version.py +++ b/rust2rpm/tests/test_version.py @@ -149,9 +149,13 @@ def test_coerce(version, coerced_version): "v1, op, v2, expected", [ (Version(0, 2, 2, None, None), CargoSemVer.KIND_GT, Version(0, 3, 5, None, None), False), + (Version(0, 2, 2, None, None), CargoSemVer.KIND_LT, Version(0, 3, 5, None, None), True), (Version(0, 2, 2, None, None), CargoSemVer.KIND_GTE, Version(0, 3, 5, None, None), False), + (Version(0, 2, 2, None, None), CargoSemVer.KIND_LTE, Version(0, 3, 5, None, None), True), (Version(0, 3, 5, None, None), CargoSemVer.KIND_LT, Version(0, 2, 2, None, None), False), + (Version(0, 3, 5, None, None), CargoSemVer.KIND_GT, Version(0, 2, 2, None, None), True), (Version(0, 3, 5, None, None), CargoSemVer.KIND_LTE, Version(0, 2, 2, None, None), False), + (Version(0, 3, 5, None, None), CargoSemVer.KIND_GTE, Version(0, 2, 2, None, None), True), ], ) def test_eval(v1, op, v2, expected):