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

70 lines
1.7 KiB
Python
Raw Normal View History

2015-12-22 01:49:25 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2015-2019 Mike Fährmann
2015-12-22 01:49:25 +01:00
#
# 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
import util # noqa
from gallery_dl import extractor
from test.test_results import ResultJob, setup_test_config
2015-12-22 01:49:25 +01:00
TESTDATA_FMT = """
test = ("{}", {{
2015-12-22 01:49:25 +01:00
"url": "{}",
"keyword": "{}",
"content": "{}",
}})
2015-12-22 01:49:25 +01:00
"""
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
setup_test_config()
for url in urls:
tjob = ResultJob(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
2020-03-25 22:06:38 +01:00
data = (tjob.url_hash.hexdigest(),
tjob.kwdict_hash.hexdigest(),
tjob.content_hash.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
2015-12-22 01:49:25 +01:00
if __name__ == '__main__':
main()