1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00
gallery-dl/test/test_extractors.py

52 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2016-12-09 01:15:40 +01:00
# Copyright 2015, 2016 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
2016-07-23 17:50:42 +02:00
from gallery_dl import extractor, job, config, cache
2015-12-15 23:45:40 +01:00
class TestExtractors(unittest.TestCase):
2016-02-18 15:53:53 +01:00
def setUp(self):
2015-12-13 03:56:29 +01:00
config.load()
config.set(("cache", "file"), ":memory:")
def run_test(self, extr, url, result):
2016-07-23 17:50:42 +02:00
hjob = job.HashJob(url, "content" in result)
self.assertEqual(extr, hjob.extractor.__class__)
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"])
if "content" in result:
self.assertEqual(hjob.hash_content.hexdigest(), result["content"])
2016-02-18 15:53:53 +01:00
def generate_test(extr):
def test(self):
2016-12-09 01:15:40 +01:00
print("\n", extr.__name__, sep="")
2016-02-18 15:53:53 +01:00
for url, result in extr.test:
print(url)
self.run_test(extr, url, result)
2016-02-18 15:53:53 +01:00
return test
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:
2016-12-09 01:15:40 +01:00
if hasattr(extr, "test") and extr.test:
2016-02-18 15:53:53 +01:00
name = "test_" + extr.__name__
test = generate_test(extr)
setattr(TestExtractors, name, test)
del sys.argv[1:]
unittest.main(warnings='ignore')