2016-12-10 00:01:00 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2016-2023 Mike Fährmann
|
2016-12-10 00:01:00 +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.
|
|
|
|
|
|
|
|
"""Utility extractor to execute tests of other extractors"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import extractor, exception
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2016-12-10 00:01:00 +01:00
|
|
|
class TestExtractor(Extractor):
|
|
|
|
"""Extractor to select and run the test URLs of other extractors
|
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
The general form is 'test:<categories>:<subcategories>:<indices>', where
|
|
|
|
<categories> and <subcategories> are comma-separated (sub)category names
|
|
|
|
and <indices> is a comma-seperated list of array indices.
|
|
|
|
To select all possible values for a field use the star '*' character or
|
|
|
|
leave the field empty.
|
2016-12-10 00:01:00 +01:00
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
Examples:
|
|
|
|
- test:pixiv
|
|
|
|
run all pixiv tests
|
2016-12-10 00:01:00 +01:00
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
- test:pixiv:user,favorite:0
|
|
|
|
run the first test of the PixivUser- and PixivFavoriteExtractor
|
2016-12-10 00:01:00 +01:00
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
- test:
|
|
|
|
run all tests
|
2016-12-10 00:01:00 +01:00
|
|
|
"""
|
|
|
|
category = "test"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = r"t(?:est)?:([^:]*)(?::([^:]*)(?::(\*|[\d,]*))?)?$"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "test:CATEGORY"
|
2016-12-10 00:01:00 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
Extractor.__init__(self, match)
|
2017-05-19 14:04:52 +02:00
|
|
|
categories, subcategories, indices = match.groups()
|
|
|
|
self.categories = self._split(categories)
|
|
|
|
self.subcategories = self._split(subcategories)
|
|
|
|
self.indices = self._split(indices) or self
|
2016-12-10 00:01:00 +01:00
|
|
|
|
|
|
|
def items(self):
|
2017-05-19 14:04:52 +02:00
|
|
|
extractors = extractor.extractors()
|
2016-12-10 00:01:00 +01:00
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
if self.categories:
|
|
|
|
extractors = [
|
|
|
|
extr for extr in extractors
|
|
|
|
if extr.category in self.categories
|
2016-12-10 00:01:00 +01:00
|
|
|
]
|
2017-05-19 14:04:52 +02:00
|
|
|
|
|
|
|
if self.subcategories:
|
|
|
|
extractors = [
|
|
|
|
extr for extr in extractors
|
|
|
|
if extr.subcategory in self.subcategories
|
2016-12-17 13:23:29 +01:00
|
|
|
]
|
2016-12-10 00:01:00 +01:00
|
|
|
|
2017-05-19 14:04:52 +02:00
|
|
|
tests = [
|
|
|
|
test
|
|
|
|
for extr in extractors
|
2019-02-06 17:24:44 +01:00
|
|
|
for index, test in enumerate(extr._get_tests())
|
2017-05-19 14:04:52 +02:00
|
|
|
if str(index) in self.indices
|
|
|
|
]
|
|
|
|
|
2016-12-10 00:01:00 +01:00
|
|
|
if not tests:
|
|
|
|
raise exception.NotFoundError("test")
|
|
|
|
|
|
|
|
for test in tests:
|
2017-09-12 16:19:00 +02:00
|
|
|
yield Message.Queue, test[0], {}
|
2017-05-19 14:04:52 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def __contains__(_):
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _split(value):
|
|
|
|
if value and value != "*":
|
|
|
|
return value.split(",")
|
|
|
|
return None
|