make extractor unittest discoverable
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2015, 2016 Mike Fährmann
|
# Copyright 2015-2017 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from gallery_dl import extractor, job, config, cache
|
from gallery_dl import extractor, job, config
|
||||||
|
|
||||||
|
|
||||||
class TestExtractors(unittest.TestCase):
|
class TestExtractors(unittest.TestCase):
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ class TestExtractors(unittest.TestCase):
|
|||||||
config.load()
|
config.load()
|
||||||
config.set(("cache", "file"), ":memory:")
|
config.set(("cache", "file"), ":memory:")
|
||||||
|
|
||||||
def run_test(self, extr, url, result):
|
def _run_test(self, extr, url, result):
|
||||||
hjob = job.HashJob(url, "content" in result)
|
hjob = job.HashJob(url, "content" in result)
|
||||||
self.assertEqual(extr, hjob.extractor.__class__)
|
self.assertEqual(extr, hjob.extractor.__class__)
|
||||||
if "exception" in result:
|
if "exception" in result:
|
||||||
@@ -31,24 +32,26 @@ class TestExtractors(unittest.TestCase):
|
|||||||
self.assertEqual(hjob.hash_content.hexdigest(), result["content"])
|
self.assertEqual(hjob.hash_content.hexdigest(), result["content"])
|
||||||
|
|
||||||
|
|
||||||
def generate_test(extr):
|
# dynamically genetate tests
|
||||||
|
def _generate_test(extr, tcase):
|
||||||
def test(self):
|
def test(self):
|
||||||
print("\n", extr.__name__, sep="")
|
url, result = tcase
|
||||||
for url, result in extr.test:
|
print("\n", url, sep="")
|
||||||
print(url)
|
self._run_test(extr, url, result)
|
||||||
self.run_test(extr, url, result)
|
|
||||||
return test
|
return test
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
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") and extr.test:
|
|
||||||
name = "test_" + extr.__name__
|
|
||||||
test = generate_test(extr)
|
|
||||||
setattr(TestExtractors, name, test)
|
|
||||||
del sys.argv[1:]
|
|
||||||
unittest.main(warnings='ignore')
|
unittest.main(warnings='ignore')
|
||||||
|
|||||||
Reference in New Issue
Block a user