update build_testresult_db.py script
This commit is contained in:
@@ -521,18 +521,23 @@ class TestJob(DownloadJob):
|
|||||||
class DataJob(Job):
|
class DataJob(Job):
|
||||||
"""Collect extractor results and dump them"""
|
"""Collect extractor results and dump them"""
|
||||||
|
|
||||||
def __init__(self, url, parent=None, file=sys.stdout):
|
def __init__(self, url, parent=None, file=sys.stdout, ensure_ascii=True):
|
||||||
Job.__init__(self, url, parent)
|
Job.__init__(self, url, parent)
|
||||||
self.file = file
|
self.file = file
|
||||||
self.data = []
|
self.data = []
|
||||||
|
self.ascii = config.get(("output", "ascii"), ensure_ascii)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# collect data
|
# collect data
|
||||||
try:
|
try:
|
||||||
for msg in self.extractor:
|
for msg in self.extractor:
|
||||||
self.dispatch(msg)
|
self.dispatch(msg)
|
||||||
|
except exception.StopExtraction:
|
||||||
|
pass
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.data.append((exc.__class__.__name__, str(exc)))
|
self.data.append((exc.__class__.__name__, str(exc)))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -543,8 +548,7 @@ class DataJob(Job):
|
|||||||
# dump to 'file'
|
# dump to 'file'
|
||||||
json.dump(
|
json.dump(
|
||||||
self.data, self.file,
|
self.data, self.file,
|
||||||
sort_keys=True, indent=2,
|
sort_keys=True, indent=2, ensure_ascii=self.ascii,
|
||||||
ensure_ascii=config.get(("output", "ascii"), True),
|
|
||||||
)
|
)
|
||||||
self.file.write("\n")
|
self.file.write("\n")
|
||||||
|
|
||||||
|
|||||||
@@ -7,27 +7,47 @@ import datetime
|
|||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
||||||
from gallery_dl import extractor, job, config
|
from gallery_dl import extractor, job, config
|
||||||
|
from test.test_results import setup_test_config
|
||||||
|
|
||||||
|
|
||||||
|
# filter test cases
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
([url[0] for url in extr.test if url[1]], extr)
|
(idx, extr, url, result)
|
||||||
for extr in extractor.extractors()
|
|
||||||
if hasattr(extr, "test")
|
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.test)
|
||||||
|
if result
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
|
||||||
tests = [
|
# setup target directory
|
||||||
(urls, extr)
|
|
||||||
for urls, extr in tests
|
|
||||||
if extr.category in sys.argv
|
|
||||||
]
|
|
||||||
|
|
||||||
path = os.path.join(ROOTDIR, "archive/testdb", str(datetime.date.today()))
|
path = os.path.join(ROOTDIR, "archive/testdb", str(datetime.date.today()))
|
||||||
os.makedirs(path, exist_ok=True)
|
os.makedirs(path, exist_ok=True)
|
||||||
config.load()
|
|
||||||
|
|
||||||
for urls, extr in tests:
|
|
||||||
for i, url in enumerate(urls):
|
for idx, extr, url, result in tests:
|
||||||
name = "%s-%s-%d.json" % (extr.category, extr.subcategory, i)
|
|
||||||
print(name)
|
# 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"]:
|
||||||
|
config.set(key.split("."), value)
|
||||||
|
if "range" in result:
|
||||||
|
config.set(("image-range",), result["range"])
|
||||||
|
|
||||||
|
# write test data
|
||||||
|
try:
|
||||||
with open(os.path.join(path, name), "w") as outfile:
|
with open(os.path.join(path, name), "w") as outfile:
|
||||||
job.DataJob(url, file=outfile).run()
|
job.DataJob(url, file=outfile, ensure_ascii=False).run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.exit()
|
||||||
|
|||||||
@@ -28,23 +28,29 @@ BROKEN = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def setup_test_config():
|
||||||
|
name = "gallerydl"
|
||||||
|
email = "gallerydl@openaliasbox.org"
|
||||||
|
|
||||||
|
config.clear()
|
||||||
|
config.set(("cache", "file"), ":memory:")
|
||||||
|
config.set(("downloader", "part"), False)
|
||||||
|
config.set(("extractor", "timeout"), 60)
|
||||||
|
config.set(("extractor", "username"), name)
|
||||||
|
config.set(("extractor", "password"), name)
|
||||||
|
config.set(("extractor", "nijie", "username"), email)
|
||||||
|
config.set(("extractor", "seiga", "username"), email)
|
||||||
|
config.set(("extractor", "deviantart", "client-id"), "7777")
|
||||||
|
config.set(("extractor", "deviantart", "client-secret"),
|
||||||
|
"ff14994c744d9208e5caeec7aab4a026")
|
||||||
|
config.set(("extractor", "tumblr", "api-key"),
|
||||||
|
"0cXoHfIqVzMQcc3HESZSNsVlulGxEXGDTTZCDrRrjaa0jmuTc6")
|
||||||
|
|
||||||
|
|
||||||
class TestExtractorResults(unittest.TestCase):
|
class TestExtractorResults(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
name = "gallerydl"
|
setup_test_config()
|
||||||
email = "gallerydl@openaliasbox.org"
|
|
||||||
config.set(("cache", "file"), ":memory:")
|
|
||||||
config.set(("downloader", "part"), False)
|
|
||||||
config.set(("downloader", "timeout"), 60)
|
|
||||||
config.set(("extractor", "username"), name)
|
|
||||||
config.set(("extractor", "password"), name)
|
|
||||||
config.set(("extractor", "nijie", "username"), email)
|
|
||||||
config.set(("extractor", "seiga", "username"), email)
|
|
||||||
config.set(("extractor", "deviantart", "client-id"), "7777")
|
|
||||||
config.set(("extractor", "deviantart", "client-secret"),
|
|
||||||
"ff14994c744d9208e5caeec7aab4a026")
|
|
||||||
config.set(("extractor", "tumblr", "api-key"),
|
|
||||||
"0cXoHfIqVzMQcc3HESZSNsVlulGxEXGDTTZCDrRrjaa0jmuTc6")
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
config.clear()
|
config.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user