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:
@@ -1,5 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
## 1.7.0 - 2019-02-05
|
## 1.7.0 - 2019-02-05
|
||||||
- Added support for:
|
- Added support for:
|
||||||
- `photobucket` - http://photobucket.com/ ([#117](https://github.com/mikf/gallery-dl/issues/117))
|
- `photobucket` - http://photobucket.com/ ([#117](https://github.com/mikf/gallery-dl/issues/117))
|
||||||
|
|||||||
@@ -255,8 +255,9 @@ def main():
|
|||||||
print(extr.__doc__)
|
print(extr.__doc__)
|
||||||
print("Category:", extr.category,
|
print("Category:", extr.category,
|
||||||
"- Subcategory:", extr.subcategory)
|
"- Subcategory:", extr.subcategory)
|
||||||
if hasattr(extr, "test") and extr.test:
|
test = next(extr._get_tests(), None)
|
||||||
print("Example :", extr.test[0][0])
|
if test:
|
||||||
|
print("Example :", test[0])
|
||||||
print()
|
print()
|
||||||
else:
|
else:
|
||||||
if not args.urls and not args.inputfile:
|
if not args.urls and not args.inputfile:
|
||||||
|
|||||||
@@ -174,6 +174,21 @@ class Extractor():
|
|||||||
for cookie in cookies:
|
for cookie in cookies:
|
||||||
setcookie(cookie)
|
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):
|
class ChapterExtractor(Extractor):
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class TestExtractor(Extractor):
|
|||||||
"""
|
"""
|
||||||
category = "test"
|
category = "test"
|
||||||
pattern = [r"t(?:est)?:([^:]*)(?::([^:]*)(?::(\*|[\d,]*))?)?$"]
|
pattern = [r"t(?:est)?:([^:]*)(?::([^:]*)(?::(\*|[\d,]*))?)?$"]
|
||||||
|
test = ("test:pixiv", "test:pixiv:user,favorite:0", "test:")
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self)
|
Extractor.__init__(self)
|
||||||
@@ -59,8 +60,7 @@ class TestExtractor(Extractor):
|
|||||||
tests = [
|
tests = [
|
||||||
test
|
test
|
||||||
for extr in extractors
|
for extr in extractors
|
||||||
if hasattr(extr, "test")
|
for index, test in enumerate(extr._get_tests())
|
||||||
for index, test in enumerate(extr.test)
|
|
||||||
if str(index) in self.indices
|
if str(index) in self.indices
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
__version__ = "1.7.0"
|
__version__ = "1.7.1-dev"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import gallery_dl.extractor as extractor
|
from gallery_dl import extractor
|
||||||
from gallery_dl.extractor.common import Extractor, Message
|
from gallery_dl.extractor.common import Extractor, Message
|
||||||
from gallery_dl.extractor.directlink import DirectlinkExtractor as DLExtractor
|
from gallery_dl.extractor.directlink import DirectlinkExtractor as DLExtractor
|
||||||
|
|
||||||
@@ -101,9 +101,7 @@ class TestExtractor(unittest.TestCase):
|
|||||||
|
|
||||||
# collect testcase URLs
|
# collect testcase URLs
|
||||||
for extr in extractor.extractors():
|
for extr in extractor.extractors():
|
||||||
if not hasattr(extr, "test"):
|
for testcase in extr._get_tests():
|
||||||
continue
|
|
||||||
for testcase in extr.test:
|
|
||||||
test_urls.append((testcase[0], extr))
|
test_urls.append((testcase[0], extr))
|
||||||
|
|
||||||
# iterate over all testcase URLs
|
# iterate over all testcase URLs
|
||||||
|
|||||||
@@ -182,10 +182,8 @@ def generate_tests():
|
|||||||
|
|
||||||
# add 'test_...' methods
|
# add 'test_...' methods
|
||||||
for extr in extractors:
|
for extr in extractors:
|
||||||
if not hasattr(extr, "test") or not extr.test:
|
|
||||||
continue
|
|
||||||
name = "test_" + extr.__name__ + "_"
|
name = "test_" + extr.__name__ + "_"
|
||||||
for num, tcase in enumerate(extr.test, 1):
|
for num, tcase in enumerate(extr._get_tests(), 1):
|
||||||
test = _generate_test(extr, tcase)
|
test = _generate_test(extr, tcase)
|
||||||
test.__name__ = name + str(num)
|
test.__name__ = name + str(num)
|
||||||
setattr(TestExtractorResults, test.__name__, test)
|
setattr(TestExtractorResults, test.__name__, test)
|
||||||
|
|||||||
Reference in New Issue
Block a user