Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/scripts/create_test_data.py
5457 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# Copyright 2015-2019 Mike Fährmann
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License version 2 as
8
# published by the Free Software Foundation.
9
10
"""Create testdata for extractor tests"""
11
12
import argparse
13
14
import util # noqa
15
from gallery_dl import extractor
16
from test.test_results import ResultJob, setup_test_config
17
18
19
TESTDATA_FMT = """
20
test = ("{}", {{
21
"url": "{}",
22
"keyword": "{}",
23
"content": "{}",
24
}})
25
"""
26
27
TESTDATA_EXCEPTION_FMT = """
28
test = ("{}", {{
29
"exception": exception.{},
30
}})
31
"""
32
33
34
def main():
35
parser = argparse.ArgumentParser()
36
parser.add_argument("--content", action="store_true")
37
parser.add_argument("--recreate", action="store_true")
38
parser.add_argument("urls", nargs="*")
39
args = parser.parse_args()
40
41
if args.recreate:
42
urls = [
43
test[0]
44
for extr in extractor.extractors() if extr.category in args.urls
45
for test in extr.test
46
]
47
else:
48
urls = args.urls
49
50
setup_test_config()
51
52
for url in urls:
53
tjob = ResultJob(url, content=args.content)
54
try:
55
tjob.run()
56
except Exception as exc:
57
fmt = TESTDATA_EXCEPTION_FMT
58
data = (exc.__class__.__name__,)
59
else:
60
fmt = TESTDATA_FMT
61
data = (tjob.url_hash.hexdigest(),
62
tjob.kwdict_hash.hexdigest(),
63
tjob.content_hash.hexdigest())
64
print(tjob.extractor.__class__.__name__)
65
print(fmt.format(url, *data))
66
67
68
if __name__ == '__main__':
69
main()
70
71