2015-12-12 15:58:07 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2015 Mike Fährmann
|
|
|
|
#
|
|
|
|
# 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
|
2015-12-13 03:56:29 +01:00
|
|
|
from gallery_dl import extractor, jobs, 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()
|
2015-12-12 15:58:07 +01:00
|
|
|
|
|
|
|
def run_test(self, url, result):
|
2015-12-21 22:49:04 +01:00
|
|
|
hjob = jobs.HashJob(url, "content" in result)
|
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
|
|
|
|
|
|
|
def generate_test(extr):
|
|
|
|
def test(self):
|
|
|
|
print(extr.__name__)
|
|
|
|
for url, result in extr.test:
|
|
|
|
print(url)
|
|
|
|
self.run_test(url, result)
|
|
|
|
return test
|
|
|
|
|
|
|
|
|
2015-12-12 15:58:07 +01:00
|
|
|
if __name__ == '__main__':
|
2016-02-18 15:53:53 +01:00
|
|
|
import sys
|
|
|
|
extractors = extractor.extractors()
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
extractors = filter(lambda x: x.category in sys.argv, extractors)
|
|
|
|
for extr in extractors:
|
|
|
|
if hasattr(extr, "test"):
|
|
|
|
name = "test_" + extr.__name__
|
|
|
|
test = generate_test(extr)
|
|
|
|
setattr(TestExtractors, name, test)
|
|
|
|
del sys.argv[1:]
|
2015-12-12 15:58:07 +01:00
|
|
|
unittest.main(warnings='ignore')
|