From 505e297bd0d9fa82d6a0c62465c8b3795da83ee0 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Mon, 20 Feb 2023 10:32:59 -0800 Subject: [PATCH] mock for info log --- tests/conftest.py | 4 ++-- tests/e2e/plugins/test_date_range.py | 13 ++++++++----- tests/e2e/youtube/test_playlist.py | 8 +++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 356e0d52..f1c1d589 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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: diff --git a/tests/e2e/plugins/test_date_range.py b/tests/e2e/plugins/test_date_range.py index 3fe751a4..ebc70d27 100644 --- a/tests/e2e/plugins/test_date_range.py +++ b/tests/e2e/plugins/test_date_range.py @@ -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() diff --git a/tests/e2e/youtube/test_playlist.py b/tests/e2e/youtube/test_playlist.py index e2785951..d0f15b66 100644 --- a/tests/e2e/youtube/test_playlist.py +++ b/tests/e2e/youtube/test_playlist.py @@ -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]