From 8a11b722538c980f5234d082c908f439eeb29850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 27 Feb 2024 01:37:57 +0100 Subject: [PATCH] remove extractor/test.py (#4504) --- gallery_dl/extractor/__init__.py | 1 - gallery_dl/extractor/test.py | 81 -------------------------------- gallery_dl/util.py | 2 +- test/results/test.py | 29 ------------ test/test_cookies.py | 6 +-- test/test_downloader.py | 2 +- test/test_extractor.py | 8 ++-- test/test_postprocessor.py | 3 +- 8 files changed, 11 insertions(+), 121 deletions(-) delete mode 100644 gallery_dl/extractor/test.py delete mode 100644 test/results/test.py diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py index a6652497..591e6a86 100644 --- a/gallery_dl/extractor/__init__.py +++ b/gallery_dl/extractor/__init__.py @@ -194,7 +194,6 @@ modules = [ "directlink", "recursive", "oauth", - "test", "ytdl", "generic", ] diff --git a/gallery_dl/extractor/test.py b/gallery_dl/extractor/test.py deleted file mode 100644 index e3f9f744..00000000 --- a/gallery_dl/extractor/test.py +++ /dev/null @@ -1,81 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2016-2023 Mike Fährmann -# -# 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 - - -class TestExtractor(Extractor): - """Extractor to select and run the test URLs of other extractors - - The general form is 'test:::', where - and are comma-separated (sub)category names - and 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. - - Examples: - - test:pixiv - run all pixiv tests - - - test:pixiv:user,favorite:0 - run the first test of the PixivUser- and PixivFavoriteExtractor - - - test: - run all tests - """ - category = "test" - pattern = r"t(?:est)?:([^:]*)(?::([^:]*)(?::(\*|[\d,]*))?)?$" - example = "test:CATEGORY" - - def __init__(self, match): - Extractor.__init__(self, match) - categories, subcategories, indices = match.groups() - self.categories = self._split(categories) - self.subcategories = self._split(subcategories) - self.indices = self._split(indices) or self - - def items(self): - extractors = extractor.extractors() - - if self.categories: - extractors = [ - extr for extr in extractors - if extr.category in self.categories - ] - - if self.subcategories: - extractors = [ - extr for extr in extractors - if extr.subcategory in self.subcategories - ] - - tests = [ - test - for extr in extractors - for index, test in enumerate(extr._get_tests()) - if str(index) in self.indices - ] - - if not tests: - raise exception.NotFoundError("test") - - for test in tests: - yield Message.Queue, test[0], {} - - @staticmethod - def __contains__(_): - return True - - @staticmethod - def _split(value): - if value and value != "*": - return value.split(",") - return None diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 751c3986..bc9418f5 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -563,7 +563,7 @@ WINDOWS = (os.name == "nt") SENTINEL = object() USERAGENT = "gallery-dl/" + version.__version__ EXECUTABLE = getattr(sys, "frozen", False) -SPECIAL_EXTRACTORS = {"oauth", "recursive", "test"} +SPECIAL_EXTRACTORS = {"oauth", "recursive", "generic"} GLOBALS = { "contains" : contains, "parse_int": text.parse_int, diff --git a/test/results/test.py b/test/results/test.py deleted file mode 100644 index 54566cc7..00000000 --- a/test/results/test.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- - -# 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. - -from gallery_dl.extractor import test - - -__tests__ = ( -{ - "#url" : "test:pixiv", - "#category": ("", "test", ""), - "#class" : test.TestExtractor, -}, - -{ - "#url" : "test:pixiv:user,favorite:0", - "#category": ("", "test", ""), - "#class" : test.TestExtractor, -}, - -{ - "#url" : "test:", - "#category": ("", "test", ""), - "#class" : test.TestExtractor, -}, - -) diff --git a/test/test_cookies.py b/test/test_cookies.py index a6ad05f1..208645d1 100644 --- a/test/test_cookies.py +++ b/test/test_cookies.py @@ -63,7 +63,7 @@ class TestCookiejar(unittest.TestCase): def _test_warning(self, filename, exc): config.set((), "cookies", filename) - log = logging.getLogger("test") + log = logging.getLogger("generic") with mock.patch.object(log, "warning") as mock_warning: cookies = _get_extractor("test").cookies @@ -173,7 +173,7 @@ class TestCookieUtils(unittest.TestCase): self.assertFalse(extr.cookies_domain, "empty") now = int(time.time()) - log = logging.getLogger("test") + log = logging.getLogger("generic") extr.cookies.set("a", "1", expires=now-100) with mock.patch.object(log, "warning") as mw: @@ -212,7 +212,7 @@ URLS = { "idolcomplex": "https://idol.sankakucomplex.com/post/show/1", "nijie" : "https://nijie.info/view.php?id=1", "horne" : "https://horne.red/view.php?id=1", - "test" : "test:", + "test" : "generic:https://example.org/", } diff --git a/test/test_downloader.py b/test/test_downloader.py index f10465e5..126fa182 100644 --- a/test/test_downloader.py +++ b/test/test_downloader.py @@ -33,7 +33,7 @@ class MockDownloaderModule(Mock): class FakeJob(): def __init__(self): - self.extractor = extractor.find("test:") + self.extractor = extractor.find("generic:https://example.org/") self.extractor.initialize() self.pathfmt = path.PathFormat(self.extractor) self.out = output.NullOutput() diff --git a/test/test_extractor.py b/test/test_extractor.py index 75a0b876..6af1226c 100644 --- a/test/test_extractor.py +++ b/test/test_extractor.py @@ -45,7 +45,7 @@ class TestExtractorModule(unittest.TestCase): "https://example.org/file.jpg", "tumblr:foobar", "oauth:flickr", - "test:pixiv:", + "generic:https://example.org/", "recursive:https://example.org/document.html", ) @@ -208,7 +208,7 @@ class TestExtractorModule(unittest.TestCase): class TestExtractorWait(unittest.TestCase): def test_wait_seconds(self): - extr = extractor.find("test:") + extr = extractor.find("generic:https://example.org/") seconds = 5 until = time.time() + seconds @@ -222,7 +222,7 @@ class TestExtractorWait(unittest.TestCase): self._assert_isotime(calls[0][1][1], until) def test_wait_until(self): - extr = extractor.find("test:") + extr = extractor.find("generic:https://example.org/") until = time.time() + 5 with patch("time.sleep") as sleep, patch.object(extr, "log") as log: @@ -237,7 +237,7 @@ class TestExtractorWait(unittest.TestCase): self._assert_isotime(calls[0][1][1], until) def test_wait_until_datetime(self): - extr = extractor.find("test:") + extr = extractor.find("generic:https://example.org/") until = datetime.utcnow() + timedelta(seconds=5) until_local = datetime.now() + timedelta(seconds=5) diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index fb1d739e..0ee7cdb2 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -30,7 +30,8 @@ class MockPostprocessorModule(Mock): class FakeJob(): - def __init__(self, extr=extractor.find("test:")): + def __init__(self, extr=extractor.find("generic:https://example.org/")): + extr.directory_fmt = ("{category}",) self.extractor = extr self.pathfmt = path.PathFormat(extr) self.out = output.NullOutput()