mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
testing environment for extractor results
This commit is contained in:
parent
9ca4426b72
commit
5304e5beef
@ -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
|
||||
|
||||
|
32
test/test_extractors.py
Normal file
32
test/test_extractors.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user