diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py index 19121202..9885c8c1 100644 --- a/gallery_dl/extractor/__init__.py +++ b/gallery_dl/extractor/__init__.py @@ -52,13 +52,18 @@ modules = [ ] def find(url): - """Find extractor suitable for handling the given url""" + """Find suitable extractor for the given url""" for pattern, klass in _list_patterns(): match = re.match(pattern, url) if match: return klass(match) return None +def extractors(): + """Yield all available extractor classes""" + for _, klass in _list_patterns(): + yield klass + # -------------------------------------------------------------------- # internals diff --git a/test/test_extractors.py b/test/test_extractors.py new file mode 100644 index 00000000..eb4438f2 --- /dev/null +++ b/test/test_extractors.py @@ -0,0 +1,32 @@ +#!/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 +import gallery_dl.extractor as extractor +import gallery_dl.jobs as jobs + +class TestExttractors(unittest.TestCase): + + def test_extractors(self): + for extr in extractor.extractors(): + if not hasattr(extr, "test"): + continue + print(extr) + for url, result in extr.test: + print(url) + self.run_test(url, result) + + def run_test(self, url, result): + hjob = jobs.HashJob(url) + hjob.run() + self.assertEqual(hjob.hash_url.hexdigest(), result["url"]) + self.assertEqual(hjob.hash_keyword.hexdigest(), result["keyword"]) + +if __name__ == '__main__': + unittest.main(warnings='ignore')