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.
|
|
|
|
|
|
|
|
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):
|
2015-12-13 03:56:29 +01:00
|
|
|
config.load()
|
2016-03-08 18:01:35 +01:00
|
|
|
config.set(("cache", "file"), ":memory:")
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2017-01-09 12:27:20 +01:00
|
|
|
def _run_test(self, extr, url, result):
|
2016-07-23 17:50:42 +02:00
|
|
|
hjob = job.HashJob(url, "content" in result)
|
2016-03-08 18:01:35 +01:00
|
|
|
self.assertEqual(extr, hjob.extractor.__class__)
|
2016-12-30 01:41:17 +01:00
|
|
|
if "exception" in result:
|
|
|
|
self.assertRaises(result["exception"], hjob.run)
|
|
|
|
return
|
2015-12-12 15:58:07 +01:00
|
|
|
hjob.run()
|
2015-12-13 03:56:29 +01:00
|
|
|
if "url" in result:
|
|
|
|
self.assertEqual(hjob.hash_url.hexdigest(), result["url"])
|
|
|
|
if "keyword" in result:
|
|
|
|
self.assertEqual(hjob.hash_keyword.hexdigest(), result["keyword"])
|
2015-12-21 22:49:04 +01:00
|
|
|
if "content" in result:
|
|
|
|
self.assertEqual(hjob.hash_content.hexdigest(), result["content"])
|
2015-12-12 15:58:07 +01:00
|
|
|
|
2016-02-18 15:53:53 +01:00
|
|
|
|
2017-01-09 12:27:20 +01:00
|
|
|
# dynamically genetate tests
|
|
|
|
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-09 12:27:20 +01:00
|
|
|
for extr in extractor.extractors():
|
|
|
|
# disable extractors that require authentication for now
|
|
|
|
if hasattr(extr, "login"):
|
|
|
|
continue
|
|
|
|
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)
|
|
|
|
del test
|
|
|
|
|
2015-12-12 15:58:07 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(warnings='ignore')
|