Use pytest for sortversion tests

This commit is contained in:
Chih-Hsuan Yen 2021-01-17 23:04:48 +08:00
parent bace59de78
commit bf8a4c9298
No known key found for this signature in database
GPG Key ID: 0453A6CA23C56315
2 changed files with 14 additions and 5 deletions

View File

@ -13,13 +13,10 @@ from pkg_resources import parse_version
try:
import pyalpm
vercmp = cmp_to_key(pyalpm.vercmp)
vercmp_available = True
except ImportError:
def vercmp(k):
raise NotImplementedError("Using vercmp but pyalpm can not be imported!")
vercmp_available = False
sort_version_keys = {"parse_version": parse_version, "vercmp": vercmp}
if __name__ == '__main__':
assert(parse_version("v6.0") < parse_version("6.1"))
assert(parse_version("v6.0") > parse_version("v6.1-stable"))
assert(vercmp("v6.0") < vercmp("v6.1-stable"))

12
tests/test_sortversion.py Normal file
View File

@ -0,0 +1,12 @@
import pytest
from nvchecker.sortversion import parse_version, vercmp, vercmp_available
def test_parse_version():
assert parse_version("v6.0") < parse_version("6.1")
assert parse_version("v6.0") > parse_version("v6.1-stable")
@pytest.mark.skipif(not vercmp_available,
reason="needs pyalpm")
def test_vercmp():
assert vercmp("v6.0") < vercmp("v6.1-stable")