mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
Merge pull request #200 from yan12125/fix-regex
regex: make sure regex fails if nothing is found
This commit is contained in:
commit
4d6e87a975
2 changed files with 12 additions and 6 deletions
|
@ -22,9 +22,7 @@ async def get_version_impl(info):
|
||||||
|
|
||||||
res = await session.get(conf['url'])
|
res = await session.get(conf['url'])
|
||||||
body = res.body.decode(encoding)
|
body = res.body.decode(encoding)
|
||||||
try:
|
versions = regex.findall(body)
|
||||||
version = regex.findall(body)
|
if not versions and not conf.get('missing_ok', False):
|
||||||
except ValueError:
|
raise GetVersionError('version string not found.')
|
||||||
if not conf.get('missing_ok', False):
|
return versions
|
||||||
raise GetVersionError('version string not found.')
|
|
||||||
return version
|
|
||||||
|
|
|
@ -43,6 +43,14 @@ async def test_missing_ok(get_version, httpbin):
|
||||||
"missing_ok": True,
|
"missing_ok": True,
|
||||||
}) is None
|
}) is None
|
||||||
|
|
||||||
|
async def test_missing(get_version, httpbin):
|
||||||
|
with pytest.raises(RuntimeError):
|
||||||
|
await get_version("example", {
|
||||||
|
"source": "regex",
|
||||||
|
"url": httpbin.url + "/base64/" + base64_encode("something not there"),
|
||||||
|
"regex": "foobar",
|
||||||
|
})
|
||||||
|
|
||||||
async def test_regex_with_tokenBasic(get_version, httpbin):
|
async def test_regex_with_tokenBasic(get_version, httpbin):
|
||||||
assert await get_version("example", {
|
assert await get_version("example", {
|
||||||
"source": "regex",
|
"source": "regex",
|
||||||
|
|
Loading…
Add table
Reference in a new issue