1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 04:02:32 +01:00
gallery-dl/scripts/create_test_data.py

63 lines
1.6 KiB
Python
Raw Normal View History

2015-12-22 01:49:25 +01:00
#!/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.
"""Create testdata for extractor tests"""
import argparse
from gallery_dl import job, config, extractor
2015-12-22 01:49:25 +01:00
TESTDATA_FMT = """
test = [("{}", {{
"url": "{}",
"keyword": "{}",
"content": "{}",
}})]
"""
2017-05-27 11:33:55 +02:00
TESTDATA_EXCEPTION_FMT = """
test = [("{}", {{
2017-05-30 17:43:02 +02:00
"exception": exception.{},
2017-05-27 11:33:55 +02:00
}})]
"""
2015-12-22 01:49:25 +01:00
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--content", action="store_true")
parser.add_argument("--recreate", action="store_true")
2015-12-22 01:49:25 +01:00
parser.add_argument("urls", nargs="*")
args = parser.parse_args()
if args.recreate:
urls = [
test[0]
for extr in extractor.extractors() if extr.category in args.urls
for test in extr.test
]
else:
urls = args.urls
2015-12-22 01:49:25 +01:00
config.load()
for url in urls:
2017-03-17 09:39:46 +01:00
tjob = job.TestJob(url, content=args.content)
2017-05-27 11:33:55 +02:00
try:
tjob.run()
except Exception as exc:
fmt = TESTDATA_EXCEPTION_FMT
data = (exc.__class__.__name__,)
else:
fmt = TESTDATA_FMT
data = (tjob.hash_url.hexdigest(),
tjob.hash_keyword.hexdigest(),
tjob.hash_content.hexdigest())
2017-03-17 09:39:46 +01:00
print(tjob.extractor.__class__.__name__)
2017-05-27 11:33:55 +02:00
print(fmt.format(url, *data))
2015-12-22 01:49:25 +01:00
if __name__ == '__main__':
main()