2015-12-22 01:49:25 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-20 15:48:31 +01:00
|
|
|
# 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
|
2019-02-20 15:48:31 +01:00
|
|
|
|
2019-04-16 18:16:48 +02:00
|
|
|
import util # noqa
|
2019-02-20 15:48:31 +01:00
|
|
|
from gallery_dl import extractor
|
|
|
|
from test.test_results import ResultJob, setup_test_config
|
|
|
|
|
2015-12-22 01:49:25 +01:00
|
|
|
|
|
|
|
TESTDATA_FMT = """
|
2019-02-20 15:48:31 +01:00
|
|
|
test = ("{}", {{
|
2015-12-22 01:49:25 +01:00
|
|
|
"url": "{}",
|
|
|
|
"keyword": "{}",
|
|
|
|
"content": "{}",
|
2019-02-20 15:48:31 +01:00
|
|
|
}})
|
2015-12-22 01:49:25 +01:00
|
|
|
"""
|
|
|
|
|
2017-05-27 11:33:55 +02:00
|
|
|
TESTDATA_EXCEPTION_FMT = """
|
2019-02-20 15:48:31 +01:00
|
|
|
test = ("{}", {{
|
2017-05-30 17:43:02 +02:00
|
|
|
"exception": exception.{},
|
2019-02-20 15:48:31 +01:00
|
|
|
}})
|
2017-05-27 11:33:55 +02:00
|
|
|
"""
|
|
|
|
|
2017-10-26 15:27:42 +02:00
|
|
|
|
2015-12-22 01:49:25 +01:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--content", action="store_true")
|
2016-12-09 00:25:52 +01:00
|
|
|
parser.add_argument("--recreate", action="store_true")
|
2015-12-22 01:49:25 +01:00
|
|
|
parser.add_argument("urls", nargs="*")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-12-09 00:25:52 +01:00
|
|
|
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
|
|
|
|
|
2019-02-20 15:48:31 +01:00
|
|
|
setup_test_config()
|
|
|
|
|
2016-12-09 00:25:52 +01:00
|
|
|
for url in urls:
|
2019-02-20 15:48:31 +01:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-10-26 15:27:42 +02:00
|
|
|
|
2015-12-22 01:49:25 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|