2015-12-12 15:58:07 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-01-09 12:27:20 +01:00
|
|
|
# Copyright 2015-2017 Mike Fährmann
|
2015-12-12 15:58:07 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2017-01-10 13:41:00 +01:00
|
|
|
import sys
|
2015-12-12 15:58:07 +01:00
|
|
|
import unittest
|
2017-01-09 12:27:20 +01:00
|
|
|
from gallery_dl import extractor, job, config
|
|
|
|
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2015-12-15 23:45:40 +01:00
|
|
|
class TestExtractors(unittest.TestCase):
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2016-02-18 15:53:53 +01:00
|
|
|
def setUp(self):
|
2017-01-10 13:41:00 +01:00
|
|
|
name = "gallerydl"
|
|
|
|
email = "gallerydl@openaliasbox.org"
|
2016-03-08 18:01:35 +01:00
|
|
|
config.set(("cache", "file"), ":memory:")
|
2017-03-27 13:22:02 +02:00
|
|
|
config.set(("extractor", "username"), name)
|
|
|
|
config.set(("extractor", "password"), name)
|
2017-01-10 13:41:00 +01:00
|
|
|
config.set(("extractor", "nijie", "username"), email)
|
|
|
|
config.set(("extractor", "seiga", "username"), email)
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2017-01-09 12:27:20 +01:00
|
|
|
def _run_test(self, extr, url, result):
|
2017-06-13 23:10:42 +02:00
|
|
|
content = "content" in result if result else False
|
|
|
|
tjob = job.TestJob(url, content)
|
2017-02-26 02:06:56 +01:00
|
|
|
self.assertEqual(extr, tjob.extractor.__class__)
|
2017-06-13 23:10:42 +02:00
|
|
|
if not result:
|
|
|
|
return
|
2017-02-27 23:05:08 +01:00
|
|
|
if "exception" in result:
|
|
|
|
self.assertRaises(result["exception"], tjob.run)
|
|
|
|
return
|
2017-02-26 02:06:56 +01:00
|
|
|
tjob.run()
|
2015-12-13 03:56:29 +01:00
|
|
|
if "url" in result:
|
2017-02-26 02:06:56 +01:00
|
|
|
self.assertEqual(tjob.hash_url.hexdigest(), result["url"])
|
2015-12-13 03:56:29 +01:00
|
|
|
if "keyword" in result:
|
2017-02-26 02:06:56 +01:00
|
|
|
self.assertEqual(tjob.hash_keyword.hexdigest(), result["keyword"])
|
2015-12-21 22:49:04 +01:00
|
|
|
if "content" in result:
|
2017-02-26 02:06:56 +01:00
|
|
|
self.assertEqual(tjob.hash_content.hexdigest(), result["content"])
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2016-02-18 15:53:53 +01:00
|
|
|
|
2017-03-14 08:51:58 +01:00
|
|
|
# dynamically generate tests
|
2017-01-09 12:27:20 +01:00
|
|
|
def _generate_test(extr, tcase):
|
2016-02-18 15:53:53 +01:00
|
|
|
def test(self):
|
2017-01-09 12:27:20 +01:00
|
|
|
url, result = tcase
|
|
|
|
print("\n", url, sep="")
|
|
|
|
self._run_test(extr, url, result)
|
2016-02-18 15:53:53 +01:00
|
|
|
return test
|
|
|
|
|
2017-01-30 19:40:15 +01:00
|
|
|
|
2017-04-09 11:37:21 +02:00
|
|
|
skip = [
|
2017-07-02 08:15:12 +02:00
|
|
|
# don't work on travis-ci
|
2017-05-05 15:49:58 +02:00
|
|
|
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
|
2017-07-24 10:50:40 +02:00
|
|
|
"archivedmoe", "archiveofsins", "thebarchive",
|
2017-04-09 11:37:21 +02:00
|
|
|
# temporary issues
|
2017-07-20 14:58:47 +02:00
|
|
|
|
2017-04-09 11:37:21 +02:00
|
|
|
]
|
2017-01-10 13:41:00 +01:00
|
|
|
# enable selective testing for direct calls
|
|
|
|
if __name__ == '__main__' and len(sys.argv) > 1:
|
2017-07-02 08:15:12 +02:00
|
|
|
if sys.argv[1].lower() == "all":
|
|
|
|
extractors = extractor.extractors()
|
|
|
|
else:
|
|
|
|
extractors = [
|
|
|
|
extr for extr in extractor.extractors()
|
|
|
|
if extr.category in sys.argv
|
|
|
|
]
|
2017-01-10 13:41:00 +01:00
|
|
|
del sys.argv[1:]
|
2017-02-10 21:20:27 +01:00
|
|
|
else:
|
|
|
|
extractors = [
|
|
|
|
extr for extr in extractor.extractors()
|
|
|
|
if extr.category not in skip
|
|
|
|
]
|
|
|
|
|
2016-02-18 15:53:53 +01:00
|
|
|
|
2017-01-10 13:41:00 +01:00
|
|
|
for extr in extractors:
|
2017-01-09 12:27:20 +01:00
|
|
|
if hasattr(extr, "test") and extr.test:
|
|
|
|
name = "test_" + extr.__name__ + "_"
|
|
|
|
for num, tcase in enumerate(extr.test, 1):
|
|
|
|
test = _generate_test(extr, tcase)
|
|
|
|
test.__name__ = name + str(num)
|
|
|
|
setattr(TestExtractors, test.__name__, test)
|
2017-01-10 13:41:00 +01:00
|
|
|
del test
|
2017-01-09 12:27:20 +01:00
|
|
|
|
2015-12-12 15:58:07 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(warnings='ignore')
|