fix docker, fix defaults getting added, add debugger test

This commit is contained in:
jbannon 2022-06-14 06:03:16 +00:00
parent 4461775369
commit 7155824702
4 changed files with 70 additions and 19 deletions

View file

@ -14,8 +14,8 @@ RUN apk update --no-cache && \
python3 \ python3 \
py3-pip && \ py3-pip && \
apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/main/ \ apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/main/ \
python3=3.10.4-r0 \ python3=~3.10 \
py3-setuptools=59.4.0-r0 && \ py3-setuptools && \
apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/community/ \ apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/community/ \
py3-pip && \ py3-pip && \
mkdir -p /config && \ mkdir -p /config && \

View file

@ -21,6 +21,8 @@ from ytdl_sub.entries.entry import Entry
from ytdl_sub.utils.logger import Logger from ytdl_sub.utils.logger import Logger
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
logger = Logger.get(name="downloader")
class DownloaderValidator(StrictDictValidator, ABC): class DownloaderValidator(StrictDictValidator, ABC):
""" """
@ -106,7 +108,7 @@ class Downloader(Generic[DownloaderOptionsT, DownloaderEntryT], ABC):
""" """
self.working_directory = working_directory self.working_directory = working_directory
self.download_options = download_options self.download_options = download_options
self.ytdl_options = Downloader._configure_ytdl_options( self.ytdl_options = self._configure_ytdl_options(
ytdl_options=ytdl_options, ytdl_options=ytdl_options,
working_directory=self.working_directory, working_directory=self.working_directory,
download_archive_file_name=download_archive_file_name, download_archive_file_name=download_archive_file_name,
@ -185,8 +187,10 @@ class Downloader(Generic[DownloaderOptionsT, DownloaderEntryT], ABC):
try: try:
_ = self.extract_info(ytdl_options_overrides=ytdl_options_overrides, **kwargs) _ = self.extract_info(ytdl_options_overrides=ytdl_options_overrides, **kwargs)
except (RejectedVideoReached, ExistingVideoReached): except RejectedVideoReached:
pass logger.debug("RejectedVideoReached, stopping additional downloads")
except ExistingVideoReached:
logger.debug("ExistingVideoReached, stopping additional downloads")
return self._get_entry_dicts_from_info_json_files() return self._get_entry_dicts_from_info_json_files()

28
tests/conftest.py Normal file
View file

@ -0,0 +1,28 @@
import contextlib
import logging
from typing import Callable
from unittest.mock import MagicMock
from unittest.mock import patch
from ytdl_sub.utils.logger import Logger
@contextlib.contextmanager
def assert_debug_log(logger: logging.Logger, expected_message: str):
"""
Patches any function, but calls the original function.
Intended to see if the particular function is called.
"""
debug_logger = Logger.get()
def _wrapped_debug(*args, **kwargs):
debug_logger.info(*args, **kwargs)
with patch.object(logger, "debug", wraps=_wrapped_debug) as patched_debug:
yield
for call_args in patched_debug.call_args_list:
if expected_message in call_args.args[0]:
return
assert False, f"{expected_message} was not found in a logger.debug call"

View file

@ -2,10 +2,13 @@ from pathlib import Path
import mergedeep import mergedeep
import pytest import pytest
from conftest import assert_debug_log
from e2e.expected_download import ExpectedDownload from e2e.expected_download import ExpectedDownload
import ytdl_sub.downloaders.downloader
from ytdl_sub.config.config_file import ConfigFile from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.config.preset import Preset from ytdl_sub.config.preset import Preset
from ytdl_sub.downloaders.youtube_downloader import YoutubeChannelDownloader
from ytdl_sub.subscriptions.subscription import Subscription from ytdl_sub.subscriptions.subscription import Subscription
@ -250,9 +253,12 @@ class TestChannelAsKodiTvShow:
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory) expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
# try downloading again, ensure nothing more was downloaded # try downloading again, ensure nothing more was downloaded
# TODO: add patch around the output of download to see what entry dicts were returned with assert_debug_log(
recent_channel_subscription.download() logger=ytdl_sub.downloaders.downloader.logger,
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory) expected_message="RejectedVideoReached, stopping additional downloads",
):
recent_channel_subscription.download()
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
def test_rolling_recent_channel_download( def test_rolling_recent_channel_download(
self, self,
@ -263,18 +269,31 @@ class TestChannelAsKodiTvShow:
output_directory, output_directory,
): ):
# First, download recent vids # First, download recent vids
recent_channel_subscription.download() with assert_debug_log(
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory) logger=ytdl_sub.downloaders.downloader.logger,
expected_message="RejectedVideoReached, stopping additional downloads",
):
recent_channel_subscription.download()
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
# Then, download the rolling recent vids subscription. This should remove one of the # Then, download the rolling recent vids subscription. This should remove one of the
# two videos # two videos
rolling_recent_channel_subscription.download() with assert_debug_log(
expected_rolling_recent_channel_download.assert_files_exist( logger=ytdl_sub.downloaders.downloader.logger,
relative_directory=output_directory expected_message="ExistingVideoReached, stopping additional downloads",
) ):
rolling_recent_channel_subscription.download()
expected_rolling_recent_channel_download.assert_files_exist(
relative_directory=output_directory
)
# Invoke the rolling download again, ensure nothing has changed # Invoke the rolling download again, ensure downloading stopped early from it already
rolling_recent_channel_subscription.download() # existing
expected_rolling_recent_channel_download.assert_files_exist( with assert_debug_log(
relative_directory=output_directory logger=ytdl_sub.downloaders.downloader.logger,
) expected_message="ExistingVideoReached, stopping additional downloads",
):
rolling_recent_channel_subscription.download()
expected_rolling_recent_channel_download.assert_files_exist(
relative_directory=output_directory
)