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

@@ -255,8 +255,9 @@ def main():
print(extr.__doc__)
print("Category:", extr.category,
"- Subcategory:", extr.subcategory)
if hasattr(extr, "test") and extr.test:
print("Example :", extr.test[0][0])
test = next(extr._get_tests(), None)
if test:
print("Example :", test[0])
print()
else:
if not args.urls and not args.inputfile:

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):

View File

@@ -33,6 +33,7 @@ class TestExtractor(Extractor):
"""
category = "test"
pattern = [r"t(?:est)?:([^:]*)(?::([^:]*)(?::(\*|[\d,]*))?)?$"]
test = ("test:pixiv", "test:pixiv:user,favorite:0", "test:")
def __init__(self, match):
Extractor.__init__(self)
@@ -59,8 +60,7 @@ class TestExtractor(Extractor):
tests = [
test
for extr in extractors
if hasattr(extr, "test")
for index, test in enumerate(extr.test)
for index, test in enumerate(extr._get_tests())
if str(index) in self.indices
]

View File

@@ -6,4 +6,4 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
__version__ = "1.7.0"
__version__ = "1.7.1-dev"