mock for info log
This commit is contained in:
parent
1450d36d8d
commit
505e297bd0
3 changed files with 15 additions and 10 deletions
|
|
@ -26,7 +26,7 @@ def output_directory():
|
|||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def assert_debug_log(logger: logging.Logger, expected_message: str):
|
||||
def assert_logs(logger: logging.Logger, expected_message: str, log_level: str = "debug"):
|
||||
"""
|
||||
Patches any function, but calls the original function.
|
||||
Intended to see if the particular function is called.
|
||||
|
|
@ -36,7 +36,7 @@ def assert_debug_log(logger: logging.Logger, expected_message: str):
|
|||
def _wrapped_debug(*args, **kwargs):
|
||||
debug_logger.info(*args, **kwargs)
|
||||
|
||||
with patch.object(logger, "debug", wraps=_wrapped_debug) as patched_debug:
|
||||
with patch.object(logger, log_level, wraps=_wrapped_debug) as patched_debug:
|
||||
yield
|
||||
|
||||
for call_args in patched_debug.call_args_list:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import copy
|
|||
|
||||
import mergedeep
|
||||
import pytest
|
||||
from conftest import assert_debug_log
|
||||
from conftest import assert_logs
|
||||
from expected_download import assert_expected_downloads
|
||||
from expected_transaction_log import assert_transaction_log_matches
|
||||
|
||||
|
|
@ -67,9 +67,10 @@ class TestDateRange:
|
|||
)
|
||||
if not dry_run:
|
||||
# try downloading again, ensure nothing more was downloaded
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
log_level="info",
|
||||
):
|
||||
transaction_log = recent_channel_subscription.download()
|
||||
assert_transaction_log_matches(
|
||||
|
|
@ -137,7 +138,7 @@ class TestDateRange:
|
|||
|
||||
# First, download recent vids. Always download since we want to test dry-run
|
||||
# on the rolling recent portion.
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="RejectedVideoReached, stopping additional downloads",
|
||||
):
|
||||
|
|
@ -156,9 +157,10 @@ class TestDateRange:
|
|||
|
||||
# Then, download the rolling recent vids subscription. This should remove one of the
|
||||
# two videos
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
log_level="info",
|
||||
):
|
||||
transaction_log = rolling_recent_channel_subscription.download(dry_run=dry_run)
|
||||
|
||||
|
|
@ -182,9 +184,10 @@ class TestDateRange:
|
|||
# Invoke the rolling download again, ensure downloading stopped early from it already
|
||||
# existing
|
||||
if not dry_run:
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
log_level="info",
|
||||
):
|
||||
transaction_log = rolling_recent_channel_subscription.download()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
from conftest import assert_debug_log
|
||||
from conftest import assert_logs
|
||||
from e2e.conftest import mock_run_from_cli
|
||||
from expected_download import assert_expected_downloads
|
||||
from expected_transaction_log import assert_transaction_log_matches
|
||||
|
|
@ -82,9 +82,10 @@ class TestPlaylist:
|
|||
|
||||
# Ensure another invocation will hit ExistingVideoReached
|
||||
if not dry_run:
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
log_level="info",
|
||||
):
|
||||
_ = playlist_subscription.download()
|
||||
|
||||
|
|
@ -129,9 +130,10 @@ class TestPlaylist:
|
|||
|
||||
if not dry_run:
|
||||
# Ensure another invocation will hit ExistingVideoReached
|
||||
with assert_debug_log(
|
||||
with assert_logs(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
log_level="info",
|
||||
):
|
||||
_ = mock_run_from_cli(args=args)[0][1]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue