From 47bcf53ec1a6d1121a8994ee1e26363a16da0815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 25 Aug 2017 22:01:14 +0200 Subject: [PATCH] implement support for additional unit test result types - "pattern" matches all resulting URLs against the given regex - "count" allows to specify the amount of returned URLs --- gallery_dl/extractor/danbooru.py | 4 ++-- gallery_dl/extractor/mangapark.py | 9 ++++++--- gallery_dl/extractor/pixiv.py | 2 +- gallery_dl/extractor/yandere.py | 2 +- gallery_dl/job.py | 2 ++ test/test_extractors.py | 11 ++++++++--- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gallery_dl/extractor/danbooru.py b/gallery_dl/extractor/danbooru.py index 2ca3fe9e..e73629b0 100644 --- a/gallery_dl/extractor/danbooru.py +++ b/gallery_dl/extractor/danbooru.py @@ -51,10 +51,10 @@ class DanbooruPopularExtractor(DanbooruExtractor, booru.BooruPopularExtractor): pattern = [r"(?:https?://)?danbooru\.donmai\.us/" r"explore/posts/popular()(?:\?([^#]*))?"] test = [ + ("https://danbooru.donmai.us/explore/posts/popular", None), (("https://danbooru.donmai.us/explore/posts/popular" "?date=2017-07-17+14%3A13%3A05+-0400&scale=week"), { - "url": "2c1bafa62a587d881b709a8aea6549986fe4605b", + "count": 20, }), - ("https://danbooru.donmai.us/explore/posts/popular", None), ] api_url = "https://danbooru.donmai.us/explore/posts/popular.json" diff --git a/gallery_dl/extractor/mangapark.py b/gallery_dl/extractor/mangapark.py index 747ec36e..790249a2 100644 --- a/gallery_dl/extractor/mangapark.py +++ b/gallery_dl/extractor/mangapark.py @@ -39,15 +39,18 @@ class MangaparkChapterExtractor(Extractor): r"([^/]+/s(\d+)(?:/v([^/]+))?/c(\d+)(?:([^/]+)|/e(\d+))?)")] test = [ ("http://mangapark.me/manga/gosu/s2/c55", { + "count": 50, "keyword": "bd97ca24ef344b44292910384215ef3f1005ea2e", }), (("http://mangapark.me/manga/" "ad-astra-per-aspera-hata-kenjirou/s1/c1.2"), { - "keyword": "6e56986610cb2da9917d0d9d3217d700fbc48665", + "count": 40, + "keyword": "f28eb26b4966bebda0e761f241c2dd49e505ce13", }), ("http://mangapark.me/manga/gekkan-shoujo-nozaki-kun/s2/c70/e2/1", { - "keyword": "46a332caa65ef646c9405f69947c27f0dbc5430e", - }) + "count": 15, + "keyword": "34aa6ca3bdf5078f839cbf68ff68e39728cf248b", + }), ] def __init__(self, match): diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 3c4ea1d6..301801f9 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -266,7 +266,7 @@ class PixivRankingExtractor(PixivExtractor): test = [ (("https://www.pixiv.net/ranking.php" "?mode=daily&content=illust&date=20170818"), { - "url": "b073c74e3a6633dbdc9ba4122448f66e5211c771", + "pattern": r"^https?://i\d*\.pixiv\.net/img-original/img/.+/\d+_p", }), ("https://www.pixiv.net/ranking.php", None), ] diff --git a/gallery_dl/extractor/yandere.py b/gallery_dl/extractor/yandere.py index beb905dc..ac1290be 100644 --- a/gallery_dl/extractor/yandere.py +++ b/gallery_dl/extractor/yandere.py @@ -51,7 +51,7 @@ class YanderePopularExtractor(YandereExtractor, booru.BooruPopularExtractor): r"(by_(?:day|week|month)|recent)(?:\?([^#]*))?"] test = [ ("https://yande.re/post/popular_by_day?day=20&month=8&year=2017", { - "url": "3fb32f7108d43d70681a38366443ec825d324108", + "count": 40, }), ("https://yande.re/post/popular_recent", None), ] diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 4b022faf..d5a74e6c 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -244,6 +244,7 @@ class TestJob(DownloadJob): def __init__(self, url, content=False): DownloadJob.__init__(self, url) self.content = content + self.urllist = [] self.hash_url = hashlib.sha1() self.hash_keyword = hashlib.sha1() self.hash_content = hashlib.sha1() @@ -267,6 +268,7 @@ class TestJob(DownloadJob): def update_url(self, url): """Update the URL hash""" + self.urllist.append(url) self.hash_url.update(url.encode()) def update_keyword(self, kwdict): diff --git a/test/test_extractors.py b/test/test_extractors.py index 458cb384..d31d01f7 100644 --- a/test/test_extractors.py +++ b/test/test_extractors.py @@ -37,11 +37,16 @@ class TestExtractors(unittest.TestCase): return tjob.run() if "url" in result: - self.assertEqual(tjob.hash_url.hexdigest(), result["url"]) + self.assertEqual(result["url"], tjob.hash_url.hexdigest()) if "keyword" in result: - self.assertEqual(tjob.hash_keyword.hexdigest(), result["keyword"]) + self.assertEqual(result["keyword"], tjob.hash_keyword.hexdigest()) if "content" in result: - self.assertEqual(tjob.hash_content.hexdigest(), result["content"]) + self.assertEqual(result["content"], tjob.hash_content.hexdigest()) + if "count" in result: + self.assertEqual(len(tjob.urllist), int(result["count"])) + if "pattern" in result: + for url in tjob.urllist: + self.assertRegex(url, result["pattern"]) # dynamically generate tests