fix tests
This commit is contained in:
parent
f261bc357d
commit
ce3b4e5f2b
4 changed files with 11 additions and 15 deletions
|
|
@ -2,7 +2,6 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Tuple
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -10,7 +9,6 @@ import pytest
|
||||||
from ytdl_sub.cli.entrypoint import main
|
from ytdl_sub.cli.entrypoint import main
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.file_handler import FileHandler
|
from ytdl_sub.utils.file_handler import FileHandler
|
||||||
from ytdl_sub.utils.file_handler import FileHandlerTransactionLog
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
@ -46,7 +44,7 @@ def timestamps_file_path():
|
||||||
FileHandler.delete(tmp.name)
|
FileHandler.delete(tmp.name)
|
||||||
|
|
||||||
|
|
||||||
def mock_run_from_cli(args: str) -> List[Tuple[Subscription, FileHandlerTransactionLog]]:
|
def mock_run_from_cli(args: str) -> List[Subscription]:
|
||||||
args_list = ["ytdl-sub"] + args.split()
|
args_list = ["ytdl-sub"] + args.split()
|
||||||
with patch.object(sys, "argv", args_list):
|
with patch.object(sys, "argv", args_list):
|
||||||
return main()
|
return main()
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ class TestView:
|
||||||
args = f"view "
|
args = f"view "
|
||||||
args += "--split-chapters " if split_chapters else ""
|
args += "--split-chapters " if split_chapters else ""
|
||||||
args += f"https://www.youtube.com/playlist?list=PLBsm_SagFMmdWnCnrNtLjA9kzfrRkto4i"
|
args += f"https://www.youtube.com/playlist?list=PLBsm_SagFMmdWnCnrNtLjA9kzfrRkto4i"
|
||||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
subscriptions = mock_run_from_cli(args=args)
|
||||||
|
|
||||||
assert len(subscription_transaction_log) == 1
|
assert len(subscriptions) == 1
|
||||||
transaction_log = subscription_transaction_log[0][1]
|
transaction_log = subscriptions[0].transaction_log
|
||||||
|
|
||||||
# Ensure the video and thumbnail are recognized
|
# Ensure the video and thumbnail are recognized
|
||||||
assert len(transaction_log.files_created) == 2
|
assert len(transaction_log.files_created) == 2
|
||||||
|
|
|
||||||
|
|
@ -163,10 +163,10 @@ class TestPlaylist:
|
||||||
) as subscription_path:
|
) as subscription_path:
|
||||||
args = "--dry-run " if dry_run else ""
|
args = "--dry-run " if dry_run else ""
|
||||||
args += f"sub {subscription_path}"
|
args += f"sub {subscription_path}"
|
||||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
subscriptions = mock_run_from_cli(args=args)
|
||||||
|
|
||||||
assert len(subscription_transaction_log) == 1
|
assert len(subscriptions) == 1
|
||||||
transaction_log = subscription_transaction_log[0][1]
|
transaction_log = subscriptions[0].transaction_log
|
||||||
|
|
||||||
assert_transaction_log_matches(
|
assert_transaction_log_matches(
|
||||||
output_directory=output_directory,
|
output_directory=output_directory,
|
||||||
|
|
@ -186,7 +186,7 @@ class TestPlaylist:
|
||||||
expected_message="ExistingVideoReached, stopping additional downloads",
|
expected_message="ExistingVideoReached, stopping additional downloads",
|
||||||
log_level="debug",
|
log_level="debug",
|
||||||
):
|
):
|
||||||
transaction_log = mock_run_from_cli(args=args)[0][1]
|
transaction_log = mock_run_from_cli(args=args)[0].transaction_log
|
||||||
|
|
||||||
assert transaction_log.is_empty
|
assert transaction_log.is_empty
|
||||||
assert_expected_downloads(
|
assert_expected_downloads(
|
||||||
|
|
|
||||||
|
|
@ -187,14 +187,12 @@ class TestYoutubeVideo:
|
||||||
args = "--dry-run " if dry_run else ""
|
args = "--dry-run " if dry_run else ""
|
||||||
args += f"--config {music_video_config_path} "
|
args += f"--config {music_video_config_path} "
|
||||||
args += f"dl {single_video_preset_dict_dl_args}"
|
args += f"dl {single_video_preset_dict_dl_args}"
|
||||||
subscription_transaction_log = mock_run_from_cli(args=args)
|
subscriptions = mock_run_from_cli(args=args)
|
||||||
|
|
||||||
assert len(subscription_transaction_log) == 1
|
|
||||||
transaction_log = subscription_transaction_log[0][1]
|
|
||||||
|
|
||||||
|
assert len(subscriptions) == 1
|
||||||
assert_transaction_log_matches(
|
assert_transaction_log_matches(
|
||||||
output_directory=output_directory,
|
output_directory=output_directory,
|
||||||
transaction_log=transaction_log,
|
transaction_log=subscriptions[0].transaction_log,
|
||||||
transaction_log_summary_file_name="youtube/test_video_cli.txt",
|
transaction_log_summary_file_name="youtube/test_video_cli.txt",
|
||||||
)
|
)
|
||||||
assert_expected_downloads(
|
assert_expected_downloads(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue