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
This commit is contained in:
@@ -51,10 +51,10 @@ class DanbooruPopularExtractor(DanbooruExtractor, booru.BooruPopularExtractor):
|
|||||||
pattern = [r"(?:https?://)?danbooru\.donmai\.us/"
|
pattern = [r"(?:https?://)?danbooru\.donmai\.us/"
|
||||||
r"explore/posts/popular()(?:\?([^#]*))?"]
|
r"explore/posts/popular()(?:\?([^#]*))?"]
|
||||||
test = [
|
test = [
|
||||||
|
("https://danbooru.donmai.us/explore/posts/popular", None),
|
||||||
(("https://danbooru.donmai.us/explore/posts/popular"
|
(("https://danbooru.donmai.us/explore/posts/popular"
|
||||||
"?date=2017-07-17+14%3A13%3A05+-0400&scale=week"), {
|
"?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"
|
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+))?)")]
|
r"([^/]+/s(\d+)(?:/v([^/]+))?/c(\d+)(?:([^/]+)|/e(\d+))?)")]
|
||||||
test = [
|
test = [
|
||||||
("http://mangapark.me/manga/gosu/s2/c55", {
|
("http://mangapark.me/manga/gosu/s2/c55", {
|
||||||
|
"count": 50,
|
||||||
"keyword": "bd97ca24ef344b44292910384215ef3f1005ea2e",
|
"keyword": "bd97ca24ef344b44292910384215ef3f1005ea2e",
|
||||||
}),
|
}),
|
||||||
(("http://mangapark.me/manga/"
|
(("http://mangapark.me/manga/"
|
||||||
"ad-astra-per-aspera-hata-kenjirou/s1/c1.2"), {
|
"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", {
|
("http://mangapark.me/manga/gekkan-shoujo-nozaki-kun/s2/c70/e2/1", {
|
||||||
"keyword": "46a332caa65ef646c9405f69947c27f0dbc5430e",
|
"count": 15,
|
||||||
})
|
"keyword": "34aa6ca3bdf5078f839cbf68ff68e39728cf248b",
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ class PixivRankingExtractor(PixivExtractor):
|
|||||||
test = [
|
test = [
|
||||||
(("https://www.pixiv.net/ranking.php"
|
(("https://www.pixiv.net/ranking.php"
|
||||||
"?mode=daily&content=illust&date=20170818"), {
|
"?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),
|
("https://www.pixiv.net/ranking.php", None),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class YanderePopularExtractor(YandereExtractor, booru.BooruPopularExtractor):
|
|||||||
r"(by_(?:day|week|month)|recent)(?:\?([^#]*))?"]
|
r"(by_(?:day|week|month)|recent)(?:\?([^#]*))?"]
|
||||||
test = [
|
test = [
|
||||||
("https://yande.re/post/popular_by_day?day=20&month=8&year=2017", {
|
("https://yande.re/post/popular_by_day?day=20&month=8&year=2017", {
|
||||||
"url": "3fb32f7108d43d70681a38366443ec825d324108",
|
"count": 40,
|
||||||
}),
|
}),
|
||||||
("https://yande.re/post/popular_recent", None),
|
("https://yande.re/post/popular_recent", None),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ class TestJob(DownloadJob):
|
|||||||
def __init__(self, url, content=False):
|
def __init__(self, url, content=False):
|
||||||
DownloadJob.__init__(self, url)
|
DownloadJob.__init__(self, url)
|
||||||
self.content = content
|
self.content = content
|
||||||
|
self.urllist = []
|
||||||
self.hash_url = hashlib.sha1()
|
self.hash_url = hashlib.sha1()
|
||||||
self.hash_keyword = hashlib.sha1()
|
self.hash_keyword = hashlib.sha1()
|
||||||
self.hash_content = hashlib.sha1()
|
self.hash_content = hashlib.sha1()
|
||||||
@@ -267,6 +268,7 @@ class TestJob(DownloadJob):
|
|||||||
|
|
||||||
def update_url(self, url):
|
def update_url(self, url):
|
||||||
"""Update the URL hash"""
|
"""Update the URL hash"""
|
||||||
|
self.urllist.append(url)
|
||||||
self.hash_url.update(url.encode())
|
self.hash_url.update(url.encode())
|
||||||
|
|
||||||
def update_keyword(self, kwdict):
|
def update_keyword(self, kwdict):
|
||||||
|
|||||||
@@ -37,11 +37,16 @@ class TestExtractors(unittest.TestCase):
|
|||||||
return
|
return
|
||||||
tjob.run()
|
tjob.run()
|
||||||
if "url" in result:
|
if "url" in result:
|
||||||
self.assertEqual(tjob.hash_url.hexdigest(), result["url"])
|
self.assertEqual(result["url"], tjob.hash_url.hexdigest())
|
||||||
if "keyword" in result:
|
if "keyword" in result:
|
||||||
self.assertEqual(tjob.hash_keyword.hexdigest(), result["keyword"])
|
self.assertEqual(result["keyword"], tjob.hash_keyword.hexdigest())
|
||||||
if "content" in result:
|
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
|
# dynamically generate tests
|
||||||
|
|||||||
Reference in New Issue
Block a user