allow for simplified test data structures

Instead of a strict list of (URL, RESULTS)-tuples, extractor result
tests can now be a single (URL, RESULTS)-tuple, if it's just one test,
and "only matching" tests can now be a simple string.
This commit is contained in:
Mike Fährmann
2019-02-06 17:24:44 +01:00
parent b49c3c9991
commit bc0951d974
7 changed files with 26 additions and 12 deletions

View File

@@ -174,6 +174,21 @@ class Extractor():
for cookie in cookies:
setcookie(cookie)
@classmethod
def _get_tests(cls):
"""Yield an extractor's test cases as (URL, RESULTS) tuples"""
if not hasattr(cls, "test") or not cls.test:
return
tests = cls.test
if len(tests) == 2 and (not tests[1] or isinstance(tests[1], dict)):
tests = (tests,)
for test in tests:
if isinstance(test, str):
test = (test, None)
yield test
class ChapterExtractor(Extractor):