test main completely
This commit is contained in:
parent
1e3b6323d7
commit
4292b0c629
3 changed files with 62 additions and 2 deletions
|
|
@ -1,10 +1,15 @@
|
|||
import contextlib
|
||||
import json
|
||||
import logging
|
||||
import tempfile
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.utils.logger import Logger
|
||||
|
||||
|
||||
|
|
@ -59,3 +64,16 @@ def preset_dict_to_dl_args(preset_dict: Dict) -> str:
|
|||
return [f"--{cli_key} {current_value}"]
|
||||
|
||||
return " ".join(_recursive_preset_args(cli_key="", current_value=preset_dict))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def preset_dict_to_subscription_yaml_generator() -> Callable:
|
||||
@contextlib.contextmanager
|
||||
def _preset_dict_to_subscription_yaml_generator(subscription_name: str, preset_dict: Dict):
|
||||
subscription_dict = {subscription_name: preset_dict}
|
||||
with tempfile.NamedTemporaryFile(suffix=".yaml") as tmp_file:
|
||||
tmp_file.write(json.dumps(subscription_dict).encode("utf-8"))
|
||||
tmp_file.flush()
|
||||
yield tmp_file.name
|
||||
|
||||
return _preset_dict_to_subscription_yaml_generator
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
from conftest import assert_debug_log
|
||||
from e2e.conftest import mock_run_from_cli
|
||||
from e2e.expected_download import ExpectedDownloadFile
|
||||
from e2e.expected_download import ExpectedDownloads
|
||||
from e2e.expected_transaction_log import assert_transaction_log_matches
|
||||
|
|
@ -90,3 +91,44 @@ class TestPlaylistAsKodiMusicVideo:
|
|||
transaction_log = playlist_subscription.download()
|
||||
expected_playlist_download.assert_files_exist(relative_directory=output_directory)
|
||||
assert transaction_log.is_empty
|
||||
|
||||
@pytest.mark.parametrize("dry_run", [True, False])
|
||||
def test_playlist_download_from_cli_sub(
|
||||
self,
|
||||
preset_dict_to_subscription_yaml_generator,
|
||||
music_video_config_path,
|
||||
playlist_preset_dict,
|
||||
expected_playlist_download,
|
||||
output_directory,
|
||||
dry_run,
|
||||
):
|
||||
with preset_dict_to_subscription_yaml_generator(
|
||||
subscription_name="music_video_playlist_test", preset_dict=playlist_preset_dict
|
||||
) as subscription_path:
|
||||
args = "--dry-run " if dry_run else ""
|
||||
args += f"--config {music_video_config_path} "
|
||||
args += f"sub {subscription_path}"
|
||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
||||
|
||||
assert len(subscription_transaction_log) == 1
|
||||
transaction_log = subscription_transaction_log[0][1]
|
||||
|
||||
assert_transaction_log_matches(
|
||||
output_directory=output_directory,
|
||||
transaction_log=transaction_log,
|
||||
transaction_log_summary_file_name="youtube/test_playlist.txt",
|
||||
)
|
||||
|
||||
if not dry_run:
|
||||
expected_playlist_download.assert_files_exist(relative_directory=output_directory)
|
||||
|
||||
# Ensure another invocation will hit ExistingVideoReached
|
||||
with assert_debug_log(
|
||||
logger=ytdl_sub.downloaders.downloader.download_logger,
|
||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||
):
|
||||
transaction_log = mock_run_from_cli(args=args)[0][1]
|
||||
expected_playlist_download.assert_files_exist(
|
||||
relative_directory=output_directory
|
||||
)
|
||||
assert transaction_log.is_empty
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from ytdl_sub.utils.yaml import load_yaml
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def bad_yaml():
|
||||
def bad_yaml() -> str:
|
||||
return """
|
||||
this:
|
||||
is:
|
||||
|
|
@ -20,7 +20,7 @@ def bad_yaml():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def bad_yaml_file_path(bad_yaml):
|
||||
def bad_yaml_file_path(bad_yaml) -> str:
|
||||
with tempfile.NamedTemporaryFile(suffix=".yaml") as tmp_file:
|
||||
tmp_file.write(bad_yaml.encode("utf-8"))
|
||||
tmp_file.flush()
|
||||
|
|
|
|||
Loading…
Reference in a new issue