mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
port more tests
This commit is contained in:
parent
616cf2bc20
commit
4887ec66d9
19 changed files with 160 additions and 137 deletions
2
NEW
2
NEW
|
@ -2,3 +2,5 @@ TODO:
|
|||
* update tests
|
||||
* update README
|
||||
* create source plugin documentation
|
||||
* a script to convert old ini into new toml files
|
||||
* use github actions to run mypy
|
||||
|
|
|
@ -16,8 +16,8 @@ _ANDROID_REPO_MANIFESTS = {
|
|||
async def _get_repo_manifest(repo):
|
||||
repo_xml_url = _ANDROID_REPO_MANIFESTS[repo]
|
||||
|
||||
async with session.get(repo_xml_url) as res:
|
||||
data = (await res.read()).decode('utf-8')
|
||||
res = await session.get(repo_xml_url)
|
||||
data = res.body.decode('utf-8')
|
||||
|
||||
repo_manifest = ElementTree.fromstring(data)
|
||||
return repo_manifest
|
||||
|
|
|
@ -7,7 +7,7 @@ import sre_constants
|
|||
from nvchecker.api import session, GetVersionError
|
||||
|
||||
async def get_version(name, conf, *, cache, **kwargs):
|
||||
key = sorted(conf.items())
|
||||
key = tuple(sorted(conf.items()))
|
||||
return await cache.get(key, get_version_impl)
|
||||
|
||||
async def get_version_impl(info):
|
||||
|
@ -20,19 +20,12 @@ async def get_version_impl(info):
|
|||
|
||||
encoding = conf.get('encoding', 'latin1')
|
||||
|
||||
kwargs = {}
|
||||
headers = {}
|
||||
if conf.get('proxy'):
|
||||
kwargs["proxy"] = conf.get("proxy")
|
||||
if conf.get('user_agent'):
|
||||
headers['User-Agent'] = conf['user_agent']
|
||||
|
||||
async with session.get(conf['url'], headers=headers, **kwargs) as res:
|
||||
body = (await res.read()).decode(encoding)
|
||||
try:
|
||||
version = regex.findall(body)
|
||||
except ValueError:
|
||||
version = None
|
||||
if not conf.get('missing_ok', False):
|
||||
raise GetVersionError('version string not found.')
|
||||
return version
|
||||
res = await session.get(conf['url'])
|
||||
body = res.body.decode(encoding)
|
||||
try:
|
||||
version = regex.findall(body)
|
||||
except ValueError:
|
||||
version = None
|
||||
if not conf.get('missing_ok', False):
|
||||
raise GetVersionError('version string not found.')
|
||||
return version
|
||||
|
|
|
@ -11,10 +11,8 @@ async def get_version(name, conf, *, cache, **kwargs):
|
|||
return await cache.get(sparkle, get_version_impl)
|
||||
|
||||
async def get_version_impl(sparkle):
|
||||
async with session.get(sparkle) as res:
|
||||
resp = await res.read()
|
||||
|
||||
root = ElementTree.fromstring(resp)
|
||||
res = await session.get(sparkle)
|
||||
root = ElementTree.fromstring(res.body)
|
||||
item = root.find('./channel/item[1]/enclosure')
|
||||
|
||||
version_string = item.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}shortVersionString')
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2017 Yen Chi Hsuan <yan12125 at gmail dot com>
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_android_addon(get_version):
|
||||
assert await get_version("android-google-play-apk-expansion", {"android_sdk": "extras;google;market_apk_expansion", "repo": "addon"}) == "1.r03"
|
||||
|
||||
async def test_android_package(get_version):
|
||||
assert await get_version("android-sdk-cmake", {"android_sdk": "cmake;", "repo": "package"}) == "3.6.4111459"
|
|
@ -1,18 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
|
||||
|
||||
from flaky import flaky
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {"debianpkg": None}) == "0.1.7-1"
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg_strip_release(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {"debianpkg": None, "strip-release": 1}) == "0.1.7"
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg_suite(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {"debianpkg": None, "suite": "jessie"}) == "0.1.2-1"
|
|
@ -1,37 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
import aiohttp
|
||||
except ImportError:
|
||||
aiohttp = None
|
||||
|
||||
import pytest
|
||||
pytestmark = [
|
||||
pytest.mark.asyncio,
|
||||
pytest.mark.skipif('nvchecker.source.aiohttp_httpclient' not in sys.modules,
|
||||
reason='aiohttp no chosen'),
|
||||
]
|
||||
|
||||
async def test_proxy(get_version, monkeypatch):
|
||||
from nvchecker.source import session
|
||||
|
||||
async def fake_request(*args, proxy, **kwargs):
|
||||
class fake_response():
|
||||
status = 200
|
||||
|
||||
async def read():
|
||||
return proxy.encode("ascii")
|
||||
|
||||
def release():
|
||||
pass
|
||||
|
||||
return fake_response
|
||||
|
||||
monkeypatch.setattr(session, "nv_config", {"proxy": "255.255.255.255:65535"}, raising=False)
|
||||
monkeypatch.setattr(aiohttp.ClientSession, "_request", fake_request)
|
||||
|
||||
assert await get_version("example", {"regex": "(.+)", "url": "deadbeef"}) == "255.255.255.255:65535"
|
||||
assert await get_version("example", {"regex": "(.+)", "url": "deadbeef", "proxy": "0.0.0.0:0"}) == "0.0.0.0:0"
|
|
@ -1,14 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_pypi(get_version):
|
||||
assert await get_version("example", {"pypi": None}) == "0.1.0"
|
||||
|
||||
async def test_pypi_release(get_version):
|
||||
assert await get_version("example-test-package", {"pypi": "example-test-package"}) == "1.0.0"
|
||||
|
||||
async def test_pypi_pre_release(get_version):
|
||||
assert await get_version("example-test-package", {"pypi": "example-test-package", "use_pre_release": 1}) == "1.0.1a1"
|
|
@ -1,8 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2020 Sunlei <guizaicn@gmail.com>
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_sparkle(get_version):
|
||||
assert await get_version("example", {"sparkle": "https://sparkle-project.org/files/sparkletestcast.xml"}) == "2.0"
|
|
@ -1,20 +0,0 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
async def test_substitute_prefix(get_version):
|
||||
assert await get_version("example", {"manual": "v1.0", "prefix": "v"}) == "1.0"
|
||||
|
||||
async def test_substitute_prefix_missing_ok(get_version):
|
||||
assert await get_version("example", {"manual": "1.0", "prefix": "v"}) == "1.0"
|
||||
|
||||
async def test_substitute_regex(get_version):
|
||||
assert await get_version("example", {"manual": "r15c", "from_pattern": r"r(\d+)([a-z])", "to_pattern": r"r\1.\2"}) == "r15.c"
|
||||
|
||||
async def test_substitute_regex_missing_ok(get_version):
|
||||
assert await get_version("example", {"manual": "r15", "from_pattern": r"r(\d+)([a-z])", "to_pattern": r"r\1.\2"}) == "r15"
|
||||
|
||||
async def test_substitute_prefix_has_higher_priority(get_version):
|
||||
assert await get_version("example", {"manual": "r15", "prefix": "r", "from_pattern": r"r(\d+)", "to_pattern": r"R\1"}) == "15"
|
|
@ -39,7 +39,7 @@ async def get_version():
|
|||
async def __call__(name, config):
|
||||
entries = {name: config}
|
||||
newvers = await run(entries)
|
||||
return newvers[name]
|
||||
return newvers.get(name)
|
||||
|
||||
return __call__
|
||||
|
||||
|
|
20
tests/test_android_sdk.py
Normal file
20
tests/test_android_sdk.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2017 Yen Chi Hsuan <yan12125 at gmail dot com>
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_android_addon(get_version):
|
||||
assert await get_version("android-google-play-apk-expansion", {
|
||||
"source": "android_sdk",
|
||||
"android_sdk": "extras;google;market_apk_expansion",
|
||||
"repo": "addon",
|
||||
}) == "1.r03"
|
||||
|
||||
async def test_android_package(get_version):
|
||||
assert await get_version("android-sdk-cmake", {
|
||||
"source": "android_sdk",
|
||||
"android_sdk": "cmake;",
|
||||
"repo": "package",
|
||||
}) == "3.6.4111459"
|
|
@ -1,8 +1,12 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_anitya(get_version):
|
||||
assert await get_version("shutter", {"anitya": "fedora/shutter"}) == "0.94.3"
|
||||
assert await get_version("shutter", {
|
||||
"source": "anitya",
|
||||
"anitya": "fedora/shutter",
|
||||
}) == "0.94.3"
|
27
tests/test_debianpkg.py
Normal file
27
tests/test_debianpkg.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
|
||||
|
||||
from flaky import flaky
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {
|
||||
"source": "debianpkg",
|
||||
}) == "0.1.7-1"
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg_strip_release(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {
|
||||
"source": "debianpkg",
|
||||
"strip_release": 1,
|
||||
}) == "0.1.7"
|
||||
|
||||
@flaky(max_runs=10)
|
||||
async def test_debianpkg_suite(get_version):
|
||||
assert await get_version("sigrok-firmware-fx2lafw", {
|
||||
"source": "debianpkg",
|
||||
"suite": "jessie",
|
||||
}) == "0.1.2-1"
|
|
@ -1,5 +1,5 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import shutil
|
||||
import pytest
|
||||
|
@ -8,7 +8,12 @@ pytestmark = [pytest.mark.asyncio,
|
|||
reason="requires pacman command")]
|
||||
|
||||
async def test_pacman(get_version):
|
||||
assert await get_version("ipw2100-fw", {"pacman": None}) == "1.3-10"
|
||||
assert await get_version("ipw2100-fw", {
|
||||
"source": "pacman",
|
||||
}) == "1.3-10"
|
||||
|
||||
async def test_pacman_strip_release(get_version):
|
||||
assert await get_version("ipw2100-fw", {"pacman": None, "strip-release": 1}) == "1.3"
|
||||
assert await get_version("ipw2100-fw", {
|
||||
"source": "pacman",
|
||||
"strip_release": 1,
|
||||
}) == "1.3"
|
22
tests/test_pypi.py
Normal file
22
tests/test_pypi.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_pypi(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "pypi",
|
||||
}) == "0.1.0"
|
||||
|
||||
async def test_pypi_release(get_version):
|
||||
assert await get_version("example-test-package", {
|
||||
"source": "pypi",
|
||||
"pypi": "example-test-package",
|
||||
}) == "1.0.0"
|
||||
|
||||
async def test_pypi_pre_release(get_version):
|
||||
assert await get_version("example-test-package", {
|
||||
"source": "pypi",
|
||||
"use_pre_release": 1,
|
||||
}) == "1.0.1a1"
|
|
@ -1,5 +1,5 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2019 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import base64
|
||||
|
||||
|
@ -14,6 +14,7 @@ def base64_encode(s):
|
|||
|
||||
async def test_regex_httpbin_default_user_agent(get_version, httpbin):
|
||||
ua = await get_version("example", {
|
||||
"source": "regex",
|
||||
"url": httpbin.url + "/get",
|
||||
"regex": r'"User-Agent":\s*"([^"]+)"',
|
||||
})
|
||||
|
@ -21,6 +22,7 @@ async def test_regex_httpbin_default_user_agent(get_version, httpbin):
|
|||
|
||||
async def test_regex_httpbin_user_agent(get_version, httpbin):
|
||||
assert await get_version("example", {
|
||||
"source": "regex",
|
||||
"url": httpbin.url + "/get",
|
||||
"regex": r'"User-Agent":\s*"(\w+)"',
|
||||
"user_agent": "Meow",
|
||||
|
@ -28,12 +30,14 @@ async def test_regex_httpbin_user_agent(get_version, httpbin):
|
|||
|
||||
async def test_regex(get_version, httpbin):
|
||||
assert await get_version("example", {
|
||||
"source": "regex",
|
||||
"url": httpbin.url + "/base64/" + base64_encode("version 1.12 released"),
|
||||
"regex": r'version ([0-9.]+)',
|
||||
}) == "1.12"
|
||||
|
||||
async def test_missing_ok(get_version, httpbin):
|
||||
assert await get_version("example", {
|
||||
"source": "regex",
|
||||
"url": httpbin.url + "/base64/" + base64_encode("something not there"),
|
||||
"regex": "foobar",
|
||||
"missing_ok": True,
|
12
tests/test_sparkle.py
Normal file
12
tests/test_sparkle.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2020 Sunlei <guizaicn@gmail.com>
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_sparkle(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "sparkle",
|
||||
"sparkle": "https://sparkle-project.org/files/sparkletestcast.xml",
|
||||
}) == "2.0"
|
44
tests/test_substitute.py
Normal file
44
tests/test_substitute.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import pytest
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
async def test_substitute_prefix(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "manual",
|
||||
"manual": "v1.0",
|
||||
"prefix": "v",
|
||||
}) == "1.0"
|
||||
|
||||
async def test_substitute_prefix_missing_ok(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "manual",
|
||||
"manual": "1.0",
|
||||
"prefix": "v",
|
||||
}) == "1.0"
|
||||
|
||||
async def test_substitute_regex(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "manual",
|
||||
"manual": "r15c",
|
||||
"from_pattern": r"r(\d+)([a-z])",
|
||||
"to_pattern": r"r\1.\2",
|
||||
}) == "r15.c"
|
||||
|
||||
async def test_substitute_regex_missing_ok(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "manual",
|
||||
"manual": "r15",
|
||||
"from_pattern": r"r(\d+)([a-z])",
|
||||
"to_pattern": r"r\1.\2",
|
||||
}) == "r15"
|
||||
|
||||
async def test_substitute_prefix_has_higher_priority(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "manual",
|
||||
"manual": "r15",
|
||||
"prefix": "r",
|
||||
"from_pattern": r"r(\d+)",
|
||||
"to_pattern": r"R\1",
|
||||
}) == "15"
|
Loading…
Add table
Reference in a new issue