fix docker, fix defaults getting added, add debugger test
This commit is contained in:
parent
4461775369
commit
7155824702
4 changed files with 70 additions and 19 deletions
|
|
@ -14,8 +14,8 @@ RUN apk update --no-cache && \
|
|||
python3 \
|
||||
py3-pip && \
|
||||
apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/main/ \
|
||||
python3=3.10.4-r0 \
|
||||
py3-setuptools=59.4.0-r0 && \
|
||||
python3=~3.10 \
|
||||
py3-setuptools && \
|
||||
apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/community/ \
|
||||
py3-pip && \
|
||||
mkdir -p /config && \
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ from ytdl_sub.entries.entry import Entry
|
|||
from ytdl_sub.utils.logger import Logger
|
||||
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
|
||||
|
||||
logger = Logger.get(name="downloader")
|
||||
|
||||
|
||||
class DownloaderValidator(StrictDictValidator, ABC):
|
||||
"""
|
||||
|
|
@ -106,7 +108,7 @@ class Downloader(Generic[DownloaderOptionsT, DownloaderEntryT], ABC):
|
|||
"""
|
||||
self.working_directory = working_directory
|
||||
self.download_options = download_options
|
||||
self.ytdl_options = Downloader._configure_ytdl_options(
|
||||
self.ytdl_options = self._configure_ytdl_options(
|
||||
ytdl_options=ytdl_options,
|
||||
working_directory=self.working_directory,
|
||||
download_archive_file_name=download_archive_file_name,
|
||||
|
|
@ -185,8 +187,10 @@ class Downloader(Generic[DownloaderOptionsT, DownloaderEntryT], ABC):
|
|||
|
||||
try:
|
||||
_ = self.extract_info(ytdl_options_overrides=ytdl_options_overrides, **kwargs)
|
||||
except (RejectedVideoReached, ExistingVideoReached):
|
||||
pass
|
||||
except RejectedVideoReached:
|
||||
logger.debug("RejectedVideoReached, stopping additional downloads")
|
||||
except ExistingVideoReached:
|
||||
logger.debug("ExistingVideoReached, stopping additional downloads")
|
||||
|
||||
return self._get_entry_dicts_from_info_json_files()
|
||||
|
||||
|
|
|
|||
28
tests/conftest.py
Normal file
28
tests/conftest.py
Normal 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"
|
||||
|
|
@ -2,10 +2,13 @@ from pathlib import Path
|
|||
|
||||
import mergedeep
|
||||
import pytest
|
||||
from conftest import assert_debug_log
|
||||
from e2e.expected_download import ExpectedDownload
|
||||
|
||||
import ytdl_sub.downloaders.downloader
|
||||
from ytdl_sub.config.config_file import ConfigFile
|
||||
from ytdl_sub.config.preset import Preset
|
||||
from ytdl_sub.downloaders.youtube_downloader import YoutubeChannelDownloader
|
||||
from ytdl_sub.subscriptions.subscription import Subscription
|
||||
|
||||
|
||||
|
|
@ -250,9 +253,12 @@ class TestChannelAsKodiTvShow:
|
|||
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
|
||||
|
||||
# try downloading again, ensure nothing more was downloaded
|
||||
# TODO: add patch around the output of download to see what entry dicts were returned
|
||||
recent_channel_subscription.download()
|
||||
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
|
||||
with assert_debug_log(
|
||||
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)
|
||||
|
||||
def test_rolling_recent_channel_download(
|
||||
self,
|
||||
|
|
@ -263,18 +269,31 @@ class TestChannelAsKodiTvShow:
|
|||
output_directory,
|
||||
):
|
||||
# First, download recent vids
|
||||
recent_channel_subscription.download()
|
||||
expected_recent_channel_download.assert_files_exist(relative_directory=output_directory)
|
||||
with assert_debug_log(
|
||||
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
|
||||
# two videos
|
||||
rolling_recent_channel_subscription.download()
|
||||
expected_rolling_recent_channel_download.assert_files_exist(
|
||||
relative_directory=output_directory
|
||||
)
|
||||
with assert_debug_log(
|
||||
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
|
||||
)
|
||||
|
||||
# Invoke the rolling download again, ensure nothing has changed
|
||||
rolling_recent_channel_subscription.download()
|
||||
expected_rolling_recent_channel_download.assert_files_exist(
|
||||
relative_directory=output_directory
|
||||
)
|
||||
# Invoke the rolling download again, ensure downloading stopped early from it already
|
||||
# existing
|
||||
with assert_debug_log(
|
||||
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
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue