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
pull/40/head
Mike Fährmann 7 years ago
parent 2d0dfe9d56
commit 47bcf53ec1
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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"

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

@ -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),
]

@ -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),
]

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

@ -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

Loading…
Cancel
Save