From bf8a4c92989c5ba799cd4b500e3cf0e8684ad12b Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sun, 17 Jan 2021 23:04:48 +0800 Subject: [PATCH] Use pytest for sortversion tests --- nvchecker/sortversion.py | 7 ++----- tests/test_sortversion.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tests/test_sortversion.py diff --git a/nvchecker/sortversion.py b/nvchecker/sortversion.py index 739a104..a056c58 100644 --- a/nvchecker/sortversion.py +++ b/nvchecker/sortversion.py @@ -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")) diff --git a/tests/test_sortversion.py b/tests/test_sortversion.py new file mode 100644 index 0000000..5d5679d --- /dev/null +++ b/tests/test_sortversion.py @@ -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")