From 5304e5beef501d75d981a4640482d361af09b4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 12 Dec 2015 15:58:07 +0100 Subject: [PATCH] testing environment for extractor results --- gallery_dl/extractor/__init__.py | 7 ++++++- test/test_extractors.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/test_extractors.py 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')