forked from mikf/gallery-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_testresult_db.py
executable file
·57 lines (40 loc) · 1.31 KB
/
build_testresult_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Collect results of extractor unit tests"""
import sys
import os.path
import datetime
import util
from gallery_dl import extractor, job, config
from test.test_results import setup_test_config
# filter test cases
tests = [
(idx, extr, url, result)
for extr in extractor.extractors()
if hasattr(extr, "test") and extr.test
if len(sys.argv) <= 1 or extr.category in sys.argv
for idx, (url, result) in enumerate(extr._get_tests())
if result
]
# setup target directory
path = util.path("archive", "testdb", str(datetime.date.today()))
os.makedirs(path, exist_ok=True)
for idx, extr, url, result in tests:
# filename
name = "{}-{}-{}.json".format(extr.category, extr.subcategory, idx)
print(name)
# config values
setup_test_config()
if "options" in result:
for key, value in result["options"]:
key = key.split(".")
config.set(key[:-1], key[-1], value)
if "range" in result:
config.set((), "image-range" , result["range"])
config.set((), "chapter-range", result["range"])
# write test data
try:
with open(os.path.join(path, name), "w") as outfile:
job.DataJob(url, file=outfile, ensure_ascii=False).run()
except KeyboardInterrupt:
sys.exit()