From 0f9099aae5370c62d849b7e364080eaa4a411ab2 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Mon, 17 Aug 2020 16:31:59 +0800 Subject: [PATCH] port more tests --- nvchecker_source/bitbucket.py | 4 +-- nvchecker_source/vcs.py | 2 +- tests-old/test_bitbucket.py | 14 --------- tests-old/test_cratesio.py | 8 ----- tests-old/test_manual.py | 8 ----- tests-old/test_ubuntupkg.py | 22 -------------- tests-old/test_vcs.py | 32 -------------------- {tests-old => tests}/test_archpkg.py | 17 +++++++---- tests/test_bitbucket.py | 26 +++++++++++++++++ tests/test_cratesio.py | 10 +++++++ tests/test_manual.py | 11 +++++++ {tests-old => tests}/test_repology.py | 11 +++++-- tests/test_ubuntupkg.py | 34 ++++++++++++++++++++++ tests/test_vcs.py | 42 +++++++++++++++++++++++++++ 14 files changed, 145 insertions(+), 96 deletions(-) delete mode 100644 tests-old/test_bitbucket.py delete mode 100644 tests-old/test_cratesio.py delete mode 100644 tests-old/test_manual.py delete mode 100644 tests-old/test_ubuntupkg.py delete mode 100644 tests-old/test_vcs.py rename {tests-old => tests}/test_archpkg.py (58%) create mode 100644 tests/test_bitbucket.py create mode 100644 tests/test_cratesio.py create mode 100644 tests/test_manual.py rename {tests-old => tests}/test_repology.py (51%) create mode 100644 tests/test_ubuntupkg.py create mode 100644 tests/test_vcs.py diff --git a/nvchecker_source/bitbucket.py b/nvchecker_source/bitbucket.py index e639d8a..4d130bf 100644 --- a/nvchecker_source/bitbucket.py +++ b/nvchecker_source/bitbucket.py @@ -10,13 +10,13 @@ BITBUCKET_MAX_TAG = 'https://bitbucket.org/api/2.0/repositories/%s/refs/tags' async def get_version(name, conf, *, cache, **kwargs): repo = conf.get('bitbucket') br = conf.get('branch', '') - use_max_tag = conf.getboolean('use_max_tag', False) + use_max_tag = conf.get('use_max_tag', False) ignored_tags = conf.get("ignored_tags", "").split() sort_version_key = sort_version_keys[conf.get("sort_version_key", "parse_version")] if use_max_tag: url = BITBUCKET_MAX_TAG % repo - max_page = conf.getint('max_page', 3) + max_page = conf.get('max_page', 3) data = await _get_tags(url, max_page=max_page, cache=cache) else: diff --git a/nvchecker_source/vcs.py b/nvchecker_source/vcs.py index a351f61..f7082f5 100644 --- a/nvchecker_source/vcs.py +++ b/nvchecker_source/vcs.py @@ -26,7 +26,7 @@ def _parse_oldver(oldver): async def get_version(name, conf, *, cache, **kwargs): vcs = conf['vcs'] or '' - use_max_tag = conf.getboolean('use_max_tag', False) + use_max_tag = conf.get('use_max_tag', False) ignored_tags = conf.get("ignored_tags", "").split() oldver = conf.get('oldver') cmd = _cmd_prefix + [name, vcs] diff --git a/tests-old/test_bitbucket.py b/tests-old/test_bitbucket.py deleted file mode 100644 index 55734be..0000000 --- a/tests-old/test_bitbucket.py +++ /dev/null @@ -1,14 +0,0 @@ -# MIT licensed -# Copyright (c) 2013-2017 lilydjwg , et al. - -import pytest -pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] - -async def test_bitbucket(get_version): - assert await get_version("example", {"bitbucket": "prawee/git-tag"}) == "20150303" - -async def test_bitbucket_max_tag(get_version): - assert await get_version("example", {"bitbucket": "prawee/git-tag", "use_max_tag": 1}) == "1.7.0" - -async def test_bitbucket_max_tag_with_ignored_tags(get_version): - assert await get_version("example", {"bitbucket": "prawee/git-tag", "use_max_tag": 1, "ignored_tags": "1.6.0 1.7.0"}) == "v1.5" diff --git a/tests-old/test_cratesio.py b/tests-old/test_cratesio.py deleted file mode 100644 index 44cf525..0000000 --- a/tests-old/test_cratesio.py +++ /dev/null @@ -1,8 +0,0 @@ -# MIT licensed -# Copyright (c) 2013-2017 lilydjwg , et al. - -import pytest -pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] - -async def test_cratesio(get_version): - assert await get_version("example", {"cratesio": None}) == "0.1.0" diff --git a/tests-old/test_manual.py b/tests-old/test_manual.py deleted file mode 100644 index 7711651..0000000 --- a/tests-old/test_manual.py +++ /dev/null @@ -1,8 +0,0 @@ -# MIT licensed -# Copyright (c) 2013-2017 lilydjwg , et al. - -import pytest -pytestmark = pytest.mark.asyncio - -async def test_manual(get_version): - assert await get_version("example", {"manual": "Meow"}) == "Meow" diff --git a/tests-old/test_ubuntupkg.py b/tests-old/test_ubuntupkg.py deleted file mode 100644 index 923740d..0000000 --- a/tests-old/test_ubuntupkg.py +++ /dev/null @@ -1,22 +0,0 @@ -# MIT licensed -# Copyright (c) 2017 Felix Yan , et al. - -from flaky import flaky -import pytest -pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] - -@flaky -async def test_ubuntupkg(get_version): - assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None}) == "0.1.7-1" - -@flaky -async def test_ubuntupkg_strip_release(get_version): - assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None, "strip-release": 1}) == "0.1.7" - -@flaky -async def test_ubuntupkg_suite(get_version): - assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None, "suite": "xenial"}) == "0.1.2-1" - -@flaky -async def test_ubuntupkg_suite_with_paging(get_version): - assert await get_version("ffmpeg", {"ubuntupkg": None, "suite": "xenial"}) == "7:2.8.17-0ubuntu0.1" diff --git a/tests-old/test_vcs.py b/tests-old/test_vcs.py deleted file mode 100644 index 4e8061e..0000000 --- a/tests-old/test_vcs.py +++ /dev/null @@ -1,32 +0,0 @@ -# MIT licensed -# Copyright (c) 2013-2017 lilydjwg , et al. - -import os -import shutil -import pytest -pytestmark = pytest.mark.asyncio - - -@pytest.mark.skipif(shutil.which("git") is None, - reason="requires git command") -async def test_git(get_version): - os.path.exists("example") or os.mkdir("example") - assert await get_version("example", {"vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git"}) == "1.1.2b3cdf6134b07ae6ac77f11b586dc1ae6d1521db" - -@pytest.mark.skipif(shutil.which("hg") is None, - reason="requires hg command") -async def test_mercurial(get_version): - os.path.exists("example") or os.mkdir("example") - assert await get_version("example", {"vcs": "hg+https://bitbucket.org/pil0t/testrepo"}) == "1.1.84679e29c7d9" - -@pytest.mark.skipif(shutil.which("git") is None, - reason="requires git command") -async def test_git_max_tag(get_version): - os.path.exists("example") or os.mkdir("example") - assert await get_version("example", {"vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git", "use_max_tag": 1}) == "second_release" - -@pytest.mark.skipif(shutil.which("git") is None, - reason="requires git command") -async def test_git_max_tag_with_ignored_tags(get_version): - os.path.exists("example") or os.mkdir("example") - assert await get_version("example", {"vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git", "use_max_tag": 1, "ignored_tags": "second_release release3"}) == "first_release" diff --git a/tests-old/test_archpkg.py b/tests/test_archpkg.py similarity index 58% rename from tests-old/test_archpkg.py rename to tests/test_archpkg.py index 19bbdb3..84bb31c 100644 --- a/tests-old/test_archpkg.py +++ b/tests/test_archpkg.py @@ -1,5 +1,5 @@ # MIT licensed -# Copyright (c) 2013-2017 lilydjwg , et al. +# Copyright (c) 2013-2020 lilydjwg , et al. from flaky import flaky import pytest @@ -7,24 +7,29 @@ pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] @flaky async def test_archpkg(get_version): - assert await get_version("ipw2100-fw", {"archpkg": None}) == "1.3-10" + assert await get_version("ipw2100-fw", { + "source": "archpkg", + }) == "1.3-10" @flaky async def test_archpkg_strip_release(get_version): - assert await get_version("ipw2100-fw", {"archpkg": None, "strip-release": 1}) == "1.3" + assert await get_version("ipw2100-fw", { + "source": "archpkg", + "strip_release": True, + }) == "1.3" @flaky async def test_archpkg_provided(get_version): assert await get_version("jsoncpp", { - "archpkg": None, + "source": "archpkg", "provided": "libjsoncpp.so", }) == "24-64" @flaky async def test_archpkg_provided_strip(get_version): assert await get_version("jsoncpp", { - "archpkg": None, + "source": "archpkg", "provided": "libjsoncpp.so", - "strip-release": True, + "strip_release": True, }) == "24" diff --git a/tests/test_bitbucket.py b/tests/test_bitbucket.py new file mode 100644 index 0000000..e8f6629 --- /dev/null +++ b/tests/test_bitbucket.py @@ -0,0 +1,26 @@ +# MIT licensed +# Copyright (c) 2013-2020 lilydjwg , et al. + +import pytest +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +async def test_bitbucket(get_version): + assert await get_version("example", { + "source": "bitbucket", + "bitbucket": "prawee/git-tag", + }) == "20150303" + +async def test_bitbucket_max_tag(get_version): + assert await get_version("example", { + "source": "bitbucket", + "bitbucket": "prawee/git-tag", + "use_max_tag": True, + }) == "1.7.0" + +async def test_bitbucket_max_tag_with_ignored_tags(get_version): + assert await get_version("example", { + "source": "bitbucket", + "bitbucket": "prawee/git-tag", + "use_max_tag": True, + "ignored_tags": "1.6.0 1.7.0", + }) == "v1.5" diff --git a/tests/test_cratesio.py b/tests/test_cratesio.py new file mode 100644 index 0000000..1ab09e3 --- /dev/null +++ b/tests/test_cratesio.py @@ -0,0 +1,10 @@ +# MIT licensed +# Copyright (c) 2013-2020 lilydjwg , et al. + +import pytest +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +async def test_cratesio(get_version): + assert await get_version("example", { + "source": "cratesio", + }) == "0.1.0" diff --git a/tests/test_manual.py b/tests/test_manual.py new file mode 100644 index 0000000..1818832 --- /dev/null +++ b/tests/test_manual.py @@ -0,0 +1,11 @@ +# MIT licensed +# Copyright (c) 2013-2020 lilydjwg , et al. + +import pytest +pytestmark = pytest.mark.asyncio + +async def test_manual(get_version): + assert await get_version("example", { + "source": "manual", + "manual": "Meow", + }) == "Meow" diff --git a/tests-old/test_repology.py b/tests/test_repology.py similarity index 51% rename from tests-old/test_repology.py rename to tests/test_repology.py index 4da0b63..7491ab1 100644 --- a/tests-old/test_repology.py +++ b/tests/test_repology.py @@ -1,15 +1,20 @@ # MIT licensed -# Copyright (c) 2019 lilydjwg , et al. +# Copyright (c) 2019-2020 lilydjwg , et al. import pytest pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] async def test_repology(get_version): - assert await get_version("ssed", {"repology": None, "repo": "aur"}) == "3.62" + assert await get_version("ssed", { + "source": "repology", + "repo": "aur", + }) == "3.62" async def test_repology_no_repo(get_version): try: - assert await get_version("ssed", {"repology": None}) is None + assert await get_version("ssed", { + "source": "repology", + }) is None except RuntimeError as e: assert "repo field is required" in str(e) diff --git a/tests/test_ubuntupkg.py b/tests/test_ubuntupkg.py new file mode 100644 index 0000000..6f125c3 --- /dev/null +++ b/tests/test_ubuntupkg.py @@ -0,0 +1,34 @@ +# MIT licensed +# Copyright (c) 2020 lilydjwg , et al. +# Copyright (c) 2017 Felix Yan , et al. + +from flaky import flaky +import pytest +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +@flaky +async def test_ubuntupkg(get_version): + assert await get_version("sigrok-firmware-fx2lafw", { + "source": "ubuntupkg", + }) == "0.1.7-1" + +@flaky +async def test_ubuntupkg_strip_release(get_version): + assert await get_version("sigrok-firmware-fx2lafw", { + "source": "ubuntupkg", + "strip_release": True, + }) == "0.1.7" + +@flaky +async def test_ubuntupkg_suite(get_version): + assert await get_version("sigrok-firmware-fx2lafw", { + "source": "ubuntupkg", + "suite": "xenial", + }) == "0.1.2-1" + +@flaky +async def test_ubuntupkg_suite_with_paging(get_version): + assert await get_version("ffmpeg", { + "source": "ubuntupkg", + "suite": "xenial", + }) == "7:2.8.17-0ubuntu0.1" diff --git a/tests/test_vcs.py b/tests/test_vcs.py new file mode 100644 index 0000000..8f5b9bc --- /dev/null +++ b/tests/test_vcs.py @@ -0,0 +1,42 @@ +# MIT licensed +# Copyright (c) 2013-2020 lilydjwg , et al. + +import shutil +import pytest +pytestmark = pytest.mark.asyncio + + +@pytest.mark.skipif(shutil.which("git") is None, + reason="requires git command") +async def test_git(get_version): + assert await get_version("example", { + "source": "vcs", + "vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git", + }) == "1.1.2b3cdf6134b07ae6ac77f11b586dc1ae6d1521db" + +@pytest.mark.skipif(shutil.which("hg") is None, + reason="requires hg command") +async def test_mercurial(get_version): + assert await get_version("example", { + "source": "vcs", + "vcs": "hg+https://bitbucket.org/pil0t/testrepo", + }) == "1.1.84679e29c7d9" + +@pytest.mark.skipif(shutil.which("git") is None, + reason="requires git command") +async def test_git_max_tag(get_version): + assert await get_version("example", { + "source": "vcs", + "vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git", + "use_max_tag": 1, + }) == "second_release" + +@pytest.mark.skipif(shutil.which("git") is None, + reason="requires git command") +async def test_git_max_tag_with_ignored_tags(get_version): + assert await get_version("example", { + "source": "vcs", + "vcs": "git+https://github.com/harry-sanabria/ReleaseTestRepo.git", + "use_max_tag": 1, + "ignored_tags": "second_release release3", + }) == "first_release"