make 'path' and 'keywords' available in logging messages
Wrap all loggers used by job, extractor, downloader, and postprocessor objects into a (custom) LoggerAdapter that provides access to the underlying job, extractor, pathfmt, and kwdict objects and their properties. __init__() signatures for all downloader and postprocessor classes have been changed to take the current Job object as their first argument, instead of the current extractor or pathfmt. (#574, #575)
This commit is contained in:
@@ -12,12 +12,14 @@ import sys
|
||||
import unittest
|
||||
from unittest.mock import Mock, mock_open, patch
|
||||
|
||||
import logging
|
||||
import zipfile
|
||||
import tempfile
|
||||
from datetime import datetime, timezone as tz
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from gallery_dl import postprocessor, extractor, util, config # noqa E402
|
||||
from gallery_dl import extractor, output, util # noqa E402
|
||||
from gallery_dl import postprocessor, util, config # noqa E402
|
||||
from gallery_dl.postprocessor.common import PostProcessor # noqa E402
|
||||
|
||||
|
||||
@@ -25,6 +27,15 @@ class MockPostprocessorModule(Mock):
|
||||
__postprocessor__ = "mock"
|
||||
|
||||
|
||||
class FakeJob():
|
||||
|
||||
def __init__(self):
|
||||
self.extractor = extractor.find("test:")
|
||||
self.pathfmt = util.PathFormat(self.extractor)
|
||||
self.out = output.NullOutput()
|
||||
self.get_logger = logging.getLogger
|
||||
|
||||
|
||||
class TestPostprocessorModule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -58,9 +69,9 @@ class BasePostprocessorTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.extractor = extractor.find("test:")
|
||||
cls.dir = tempfile.TemporaryDirectory()
|
||||
config.set((), "base-directory", cls.dir.name)
|
||||
cls.job = FakeJob()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@@ -74,12 +85,12 @@ class BasePostprocessorTest(unittest.TestCase):
|
||||
if data is not None:
|
||||
kwdict.update(data)
|
||||
|
||||
self.pathfmt = util.PathFormat(self.extractor)
|
||||
self.pathfmt = self.job.pathfmt
|
||||
self.pathfmt.set_directory(kwdict)
|
||||
self.pathfmt.set_filename(kwdict)
|
||||
|
||||
pp = postprocessor.find(self.__class__.__name__[:-4].lower())
|
||||
return pp(self.pathfmt, options)
|
||||
return pp(self.job, options)
|
||||
|
||||
|
||||
class ClassifyTest(BasePostprocessorTest):
|
||||
|
||||
Reference in New Issue
Block a user