1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 12:12:34 +01:00

testing environment for extractor results

This commit is contained in:
Mike Fährmann 2015-12-12 15:58:07 +01:00
parent 9ca4426b72
commit 5304e5beef
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 38 additions and 1 deletions

View File

@ -52,13 +52,18 @@ modules = [
] ]
def find(url): def find(url):
"""Find extractor suitable for handling the given url""" """Find suitable extractor for the given url"""
for pattern, klass in _list_patterns(): for pattern, klass in _list_patterns():
match = re.match(pattern, url) match = re.match(pattern, url)
if match: if match:
return klass(match) return klass(match)
return None return None
def extractors():
"""Yield all available extractor classes"""
for _, klass in _list_patterns():
yield klass
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# internals # internals

32
test/test_extractors.py Normal file
View File

@ -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')