[DEV] Bump black from 22.3.0 to 24.4.2 (#973)
* Bump black from 22.3.0 to 24.4.2 Bumps [black](https://github.com/psf/black) from 22.3.0 to 24.4.2. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/22.3.0...24.4.2) --- updated-dependencies: - dependency-name: black dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * run linter --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jesse Bannon <jbann1994@gmail.com>
This commit is contained in:
parent
caad4598fc
commit
ec58a80660
16 changed files with 280 additions and 204 deletions
|
|
@ -47,7 +47,7 @@ test = [
|
|||
"pytest-rerunfailures~=14.0",
|
||||
]
|
||||
lint = [
|
||||
"black==22.3.0",
|
||||
"black==24.4.2",
|
||||
"isort==5.13.2",
|
||||
"pylint==2.13.5",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@ parser.add_argument("-v", "--version", action="version", version="%(prog)s " + _
|
|||
_add_shared_arguments(parser, suppress_defaults=False)
|
||||
|
||||
subparsers = parser.add_subparsers(dest="subparser")
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# SUBSCRIPTION PARSER
|
||||
class SubArguments:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ _DUMMY_ENTRY_VARIABLES: Dict[str, str] = {
|
|||
name: to_variable_dependency_format_string(
|
||||
# pylint: disable=protected-access
|
||||
script=BASE_SCRIPT,
|
||||
parsed_format_string=BASE_SCRIPT._variables[name]
|
||||
parsed_format_string=BASE_SCRIPT._variables[name],
|
||||
# pylint: enable=protected-access
|
||||
)
|
||||
for name in BASE_SCRIPT.variable_names
|
||||
|
|
|
|||
|
|
@ -248,9 +248,11 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
|
|||
self._download_ytdl_options_builder.clone()
|
||||
.add(self.ytdl_option_defaults(), before=True)
|
||||
.add(
|
||||
self.plugin_options.urls.list[url_idx].ytdl_options.dict
|
||||
if url_idx is not None
|
||||
else None,
|
||||
(
|
||||
self.plugin_options.urls.list[url_idx].ytdl_options.dict
|
||||
if url_idx is not None
|
||||
else None
|
||||
),
|
||||
before=True,
|
||||
)
|
||||
.to_dict()
|
||||
|
|
@ -352,9 +354,11 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
|
|||
url_idx=entry.get(v.ytdl_sub_input_url_index, int)
|
||||
),
|
||||
is_downloaded_fn=None if self.is_dry_run else entry.is_downloaded,
|
||||
is_thumbnail_downloaded_fn=None
|
||||
if (self.is_dry_run or not self.is_entry_thumbnails_enabled)
|
||||
else entry.is_thumbnail_downloaded_via_ytdlp,
|
||||
is_thumbnail_downloaded_fn=(
|
||||
None
|
||||
if (self.is_dry_run or not self.is_entry_thumbnails_enabled)
|
||||
else entry.is_thumbnail_downloaded_via_ytdlp
|
||||
),
|
||||
url=entry.webpage_url,
|
||||
)
|
||||
return Entry(
|
||||
|
|
|
|||
|
|
@ -263,13 +263,13 @@ class ChaptersPlugin(Plugin[ChaptersOptions]):
|
|||
"force_keyframes": self.plugin_options.force_key_frames,
|
||||
}
|
||||
if self.plugin_options.remove_sponsorblock_categories is not None:
|
||||
remove_chapters_post_processor[
|
||||
"remove_sponsor_segments"
|
||||
] = self.plugin_options.remove_sponsorblock_categories
|
||||
remove_chapters_post_processor["remove_sponsor_segments"] = (
|
||||
self.plugin_options.remove_sponsorblock_categories
|
||||
)
|
||||
if self.plugin_options.remove_chapters_regex is not None:
|
||||
remove_chapters_post_processor[
|
||||
"remove_chapters_patterns"
|
||||
] = self.plugin_options.remove_chapters_regex
|
||||
remove_chapters_post_processor["remove_chapters_patterns"] = (
|
||||
self.plugin_options.remove_chapters_regex
|
||||
)
|
||||
|
||||
if self.plugin_options.embed_chapters:
|
||||
builder.add(
|
||||
|
|
|
|||
|
|
@ -159,9 +159,9 @@ class SplitByChaptersPlugin(SplitPlugin[SplitByChaptersOptions]):
|
|||
|
||||
metadata_value_dict = {}
|
||||
if self.is_dry_run:
|
||||
metadata_value_dict[
|
||||
"Warning"
|
||||
] = "Dry-run assumes embedded chapters with no modifications"
|
||||
metadata_value_dict["Warning"] = (
|
||||
"Dry-run assumes embedded chapters with no modifications"
|
||||
)
|
||||
|
||||
metadata_value_dict["Source Title"] = new_entry.title
|
||||
metadata_value_dict["Segment"] = f"{timestamp_begin} - {timestamp_end}"
|
||||
|
|
|
|||
|
|
@ -74,13 +74,13 @@ class BaseSubscription(ABC):
|
|||
}
|
||||
)
|
||||
|
||||
self._enhanced_download_archive: Optional[
|
||||
EnhancedDownloadArchive
|
||||
] = _initialize_download_archive(
|
||||
output_options=self.output_options,
|
||||
overrides=self.overrides,
|
||||
working_directory=self.working_directory,
|
||||
output_directory=self.output_directory,
|
||||
self._enhanced_download_archive: Optional[EnhancedDownloadArchive] = (
|
||||
_initialize_download_archive(
|
||||
output_options=self.output_options,
|
||||
overrides=self.overrides,
|
||||
working_directory=self.working_directory,
|
||||
output_directory=self.output_directory,
|
||||
)
|
||||
)
|
||||
|
||||
# Add post-archive variables
|
||||
|
|
|
|||
|
|
@ -143,9 +143,9 @@ class SubscriptionValueValidator(SubscriptionLeafValidator, StringValidator):
|
|||
presets=presets,
|
||||
indent_overrides=indent_overrides,
|
||||
)
|
||||
self._overrides_to_add[
|
||||
SubscriptionVariables.subscription_value().variable_name
|
||||
] = self.value
|
||||
self._overrides_to_add[SubscriptionVariables.subscription_value().variable_name] = (
|
||||
self.value
|
||||
)
|
||||
|
||||
|
||||
class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValidator):
|
||||
|
|
@ -170,9 +170,9 @@ class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValid
|
|||
for idx, list_value in enumerate(self.list):
|
||||
# Write the first list value into subscription_value as well
|
||||
if idx == 0:
|
||||
self._overrides_to_add[
|
||||
SubscriptionVariables.subscription_value().variable_name
|
||||
] = list_value.value
|
||||
self._overrides_to_add[SubscriptionVariables.subscription_value().variable_name] = (
|
||||
list_value.value
|
||||
)
|
||||
|
||||
self._overrides_to_add[
|
||||
SubscriptionVariables.subscription_value_i(index=idx).variable_name
|
||||
|
|
@ -219,9 +219,9 @@ class SubscriptionMapValidator(SubscriptionLeafValidator, LiteralDictValidator):
|
|||
presets=presets,
|
||||
indent_overrides=indent_overrides,
|
||||
)
|
||||
self._overrides_to_add[
|
||||
SubscriptionVariables.subscription_map().variable_name
|
||||
] = ScriptUtils.to_script(self.dict)
|
||||
self._overrides_to_add[SubscriptionVariables.subscription_map().variable_name] = (
|
||||
ScriptUtils.to_script(self.dict)
|
||||
)
|
||||
|
||||
|
||||
class SubscriptionValidator(SubscriptionOutput):
|
||||
|
|
|
|||
|
|
@ -213,9 +213,10 @@ class Logger:
|
|||
@classmethod
|
||||
def _append_to_error_log(cls):
|
||||
# Any time an exception occurs, dump all debug logs into the error log
|
||||
with open(cls.debug_log_filename(), mode="r", encoding="utf-8") as debug_logs, open(
|
||||
cls.error_log_filename(), mode="a", encoding="utf-8"
|
||||
) as error_logs:
|
||||
with (
|
||||
open(cls.debug_log_filename(), mode="r", encoding="utf-8") as debug_logs,
|
||||
open(cls.error_log_filename(), mode="a", encoding="utf-8") as error_logs,
|
||||
):
|
||||
error_logs.writelines(debug_logs.readlines())
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -120,11 +120,13 @@ class TestYoutubeVideo:
|
|||
try_convert_download_thumbnail(entry=entry)
|
||||
|
||||
# Pretend the thumbnail did not download via returning nothing for its downloaded path
|
||||
with patch.object(YTDLP, "_EXTRACT_ENTRY_NUM_RETRIES", 1), patch.object(
|
||||
Entry, "try_get_ytdlp_download_thumbnail_path"
|
||||
) as mock_ytdlp_path, patch(
|
||||
"ytdl_sub.downloaders.url.downloader.try_convert_download_thumbnail",
|
||||
side_effect=delete_entry_thumb,
|
||||
with (
|
||||
patch.object(YTDLP, "_EXTRACT_ENTRY_NUM_RETRIES", 1),
|
||||
patch.object(Entry, "try_get_ytdlp_download_thumbnail_path") as mock_ytdlp_path,
|
||||
patch(
|
||||
"ytdl_sub.downloaders.url.downloader.try_convert_download_thumbnail",
|
||||
side_effect=delete_entry_thumb,
|
||||
),
|
||||
):
|
||||
mock_ytdlp_path.return_value = None
|
||||
transaction_log = single_video_subscription.download(dry_run=False)
|
||||
|
|
|
|||
|
|
@ -42,12 +42,15 @@ def test_subscription_logs_write_to_file(
|
|||
config = persist_logs_config_factory(keep_successful_logs=keep_successful_logs)
|
||||
subscription_paths = [str(music_video_subscription_path)] * num_runs
|
||||
|
||||
with patch.object(
|
||||
Subscription,
|
||||
"download",
|
||||
new=mock_subscription_download_factory(mock_success_output=mock_success_output),
|
||||
# mock datetime to be an index to be able to run instantly
|
||||
), patch("ytdl_sub.cli.entrypoint._log_time", side_effect=[str(idx) for idx in range(10)]):
|
||||
with (
|
||||
patch.object(
|
||||
Subscription,
|
||||
"download",
|
||||
new=mock_subscription_download_factory(mock_success_output=mock_success_output),
|
||||
# mock datetime to be an index to be able to run instantly
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._log_time", side_effect=[str(idx) for idx in range(10)]),
|
||||
):
|
||||
try:
|
||||
_download_subscriptions_from_yaml_files(
|
||||
config=config,
|
||||
|
|
@ -101,16 +104,19 @@ def test_update_with_info_json_requires_experimental_flag(
|
|||
default_config_path: Path,
|
||||
music_video_subscription_path: Path,
|
||||
) -> None:
|
||||
with patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
"--update-with-info-json",
|
||||
],
|
||||
), pytest.raises(ExperimentalFeatureNotEnabled):
|
||||
with (
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
"--update-with-info-json",
|
||||
],
|
||||
),
|
||||
pytest.raises(ExperimentalFeatureNotEnabled),
|
||||
):
|
||||
_ = main()
|
||||
|
|
|
|||
|
|
@ -32,19 +32,22 @@ def test_suppress_transaction_log(
|
|||
music_video_subscription_path: Path,
|
||||
file_transaction_log: Optional[str],
|
||||
) -> None:
|
||||
with patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
"--suppress-transaction-log",
|
||||
]
|
||||
+ (["--transaction-log", file_transaction_log] if file_transaction_log else []),
|
||||
), patch("ytdl_sub.cli.output_transaction_log.output_transaction_log") as mock_transaction_log:
|
||||
with (
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
"--suppress-transaction-log",
|
||||
]
|
||||
+ (["--transaction-log", file_transaction_log] if file_transaction_log else []),
|
||||
),
|
||||
patch("ytdl_sub.cli.output_transaction_log.output_transaction_log") as mock_transaction_log,
|
||||
):
|
||||
subscriptions = main()
|
||||
|
||||
assert subscriptions
|
||||
|
|
@ -82,20 +85,23 @@ def test_transaction_log_to_logger(
|
|||
default_config_path: Path,
|
||||
music_video_subscription_path: Path,
|
||||
) -> None:
|
||||
with patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
],
|
||||
), assert_logs(
|
||||
logger=transaction_logger,
|
||||
expected_message="Transaction log for Rick Astley:\n",
|
||||
log_level="info",
|
||||
with (
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--config",
|
||||
str(default_config_path),
|
||||
"sub",
|
||||
str(music_video_subscription_path),
|
||||
],
|
||||
),
|
||||
assert_logs(
|
||||
logger=transaction_logger,
|
||||
expected_message="Transaction log for Rick Astley:\n",
|
||||
log_level="info",
|
||||
),
|
||||
):
|
||||
subscriptions = main()
|
||||
assert subscriptions
|
||||
|
|
|
|||
|
|
@ -375,38 +375,47 @@ def test_subscription_file_value_applies_from_config_and_nested_and_indent_varia
|
|||
config_file: ConfigFile,
|
||||
preset_with_subscription_value_nested_presets_and_indent_variables_same_line_old_format_errors: Dict,
|
||||
):
|
||||
with mock_load_yaml(
|
||||
preset_dict=preset_with_subscription_value_nested_presets_and_indent_variables_same_line_old_format_errors
|
||||
), pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(
|
||||
"Validation error in parent_preset_2.=INDENT_1: 'INDENT_3' in '= INDENT_2 | INDENT_3' is not a preset name. "
|
||||
"To use as a subscription indent value, define it as '= INDENT_3'"
|
||||
with (
|
||||
mock_load_yaml(
|
||||
preset_dict=preset_with_subscription_value_nested_presets_and_indent_variables_same_line_old_format_errors
|
||||
),
|
||||
pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(
|
||||
"Validation error in parent_preset_2.=INDENT_1: 'INDENT_3' in '= INDENT_2 | INDENT_3' is not a preset name. "
|
||||
"To use as a subscription indent value, define it as '= INDENT_3'"
|
||||
),
|
||||
),
|
||||
):
|
||||
Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
||||
def test_subscription_file_using_conflicting_preset_name(config_file: ConfigFile):
|
||||
with mock_load_yaml(
|
||||
preset_dict={
|
||||
"= INDENTS_IN_ERR_MSG ": {"=ANOTHER": {"jellyfin_tv_show_by_date": "single value"}}
|
||||
}
|
||||
), pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(
|
||||
"Validation error in = INDENTS_IN_ERR_MSG .=ANOTHER.jellyfin_tv_show_by_date: "
|
||||
"jellyfin_tv_show_by_date conflicts with an existing preset name and cannot be used "
|
||||
"as a subscription name"
|
||||
with (
|
||||
mock_load_yaml(
|
||||
preset_dict={
|
||||
"= INDENTS_IN_ERR_MSG ": {"=ANOTHER": {"jellyfin_tv_show_by_date": "single value"}}
|
||||
}
|
||||
),
|
||||
pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(
|
||||
"Validation error in = INDENTS_IN_ERR_MSG .=ANOTHER.jellyfin_tv_show_by_date: "
|
||||
"jellyfin_tv_show_by_date conflicts with an existing preset name and cannot be used "
|
||||
"as a subscription name"
|
||||
),
|
||||
),
|
||||
):
|
||||
_ = Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
||||
def test_subscription_file_invalid_form(config_file: ConfigFile):
|
||||
with mock_load_yaml(preset_dict={"sub_name": 4332}), pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(f"Subscription value should either be a string, list, or object"),
|
||||
with (
|
||||
mock_load_yaml(preset_dict={"sub_name": 4332}),
|
||||
pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(f"Subscription value should either be a string, list, or object"),
|
||||
),
|
||||
):
|
||||
_ = Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
|
|
|||
|
|
@ -228,10 +228,11 @@ def mock_download_collection_entries(
|
|||
),
|
||||
]
|
||||
|
||||
with patch.object(
|
||||
YTDLP, "extract_info_via_info_json", new=_write_entries_to_working_dir
|
||||
), patch.object(
|
||||
MultiUrlDownloader, "_extract_entry_info_with_retry", new=lambda _, entry: entry
|
||||
with (
|
||||
patch.object(YTDLP, "extract_info_via_info_json", new=_write_entries_to_working_dir),
|
||||
patch.object(
|
||||
MultiUrlDownloader, "_extract_entry_info_with_retry", new=lambda _, entry: entry
|
||||
),
|
||||
):
|
||||
# Stub out metadata. TODO: update this if we do metadata plugins
|
||||
yield
|
||||
|
|
|
|||
|
|
@ -40,9 +40,11 @@ def mock_sys_exit():
|
|||
|
||||
@pytest.mark.parametrize("return_code", [0, 1])
|
||||
def test_main_exit_code(mock_sys_exit, return_code: int):
|
||||
with mock_sys_exit(expected_exit_code=return_code), patch(
|
||||
"src.ytdl_sub.main._main"
|
||||
) as mock_inner_main, patch.object(Logger, "cleanup") as mock_logger_cleanup:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=return_code),
|
||||
patch("src.ytdl_sub.main._main") as mock_inner_main,
|
||||
patch.object(Logger, "cleanup") as mock_logger_cleanup,
|
||||
):
|
||||
mock_inner_main.return_value = return_code
|
||||
main()
|
||||
|
||||
|
|
@ -54,9 +56,11 @@ def test_main_exit_code(mock_sys_exit, return_code: int):
|
|||
|
||||
def test_main_validation_error(capsys, mock_sys_exit):
|
||||
validation_exception = ValidationException("test exc")
|
||||
with mock_sys_exit(expected_exit_code=1), patch(
|
||||
"src.ytdl_sub.main._main", side_effect=validation_exception
|
||||
), patch.object(logging.Logger, "error") as mock_logger:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=1),
|
||||
patch("src.ytdl_sub.main._main", side_effect=validation_exception),
|
||||
patch.object(logging.Logger, "error") as mock_logger,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_logger.call_count == 1
|
||||
|
|
@ -65,11 +69,12 @@ def test_main_validation_error(capsys, mock_sys_exit):
|
|||
|
||||
def test_main_uncaught_error(capsys, mock_sys_exit, expected_uncaught_error_message):
|
||||
uncaught_error = ValueError("test")
|
||||
with mock_sys_exit(expected_exit_code=1), patch(
|
||||
"src.ytdl_sub.main._main", side_effect=uncaught_error
|
||||
), patch.object(logging.Logger, "exception") as mock_exception, patch.object(
|
||||
logging.Logger, "error"
|
||||
) as mock_error:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=1),
|
||||
patch("src.ytdl_sub.main._main", side_effect=uncaught_error),
|
||||
patch.object(logging.Logger, "exception") as mock_exception,
|
||||
patch.object(logging.Logger, "error") as mock_error,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_exception.call_count == 1
|
||||
|
|
@ -83,9 +88,11 @@ def test_main_uncaught_error(capsys, mock_sys_exit, expected_uncaught_error_mess
|
|||
|
||||
def test_main_permission_error(capsys, mock_sys_exit, expected_uncaught_error_message):
|
||||
permission_error = PermissionError("test")
|
||||
with mock_sys_exit(expected_exit_code=1), patch(
|
||||
"src.ytdl_sub.main._main", side_effect=permission_error
|
||||
), patch.object(logging.Logger, "error") as mock_error:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=1),
|
||||
patch("src.ytdl_sub.main._main", side_effect=permission_error),
|
||||
patch.object(logging.Logger, "error") as mock_error,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_error.call_count == 1
|
||||
|
|
@ -97,11 +104,15 @@ def test_main_permission_error(capsys, mock_sys_exit, expected_uncaught_error_me
|
|||
|
||||
|
||||
def test_args_after_sub_work(mock_sys_exit, tv_show_config_path):
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", tv_show_config_path, "sub", "--log-level", "verbose"],
|
||||
), patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=0),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", tv_show_config_path, "sub", "--log-level", "verbose"],
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_sub.call_count == 1
|
||||
|
|
@ -112,21 +123,25 @@ def test_args_after_sub_work(mock_sys_exit, tv_show_config_path):
|
|||
|
||||
|
||||
def test_sub_match_arguments_before(mock_sys_exit, tv_show_config_path):
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--match",
|
||||
"testA",
|
||||
"testB",
|
||||
"-c",
|
||||
tv_show_config_path,
|
||||
"sub",
|
||||
"--log-level",
|
||||
"verbose",
|
||||
],
|
||||
), patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=0),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"--match",
|
||||
"testA",
|
||||
"testB",
|
||||
"-c",
|
||||
tv_show_config_path,
|
||||
"sub",
|
||||
"--log-level",
|
||||
"verbose",
|
||||
],
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_sub.call_count == 1
|
||||
|
|
@ -137,22 +152,26 @@ def test_sub_match_arguments_before(mock_sys_exit, tv_show_config_path):
|
|||
|
||||
|
||||
def test_sub_match_arguments_after_many(mock_sys_exit, tv_show_config_path):
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"-c",
|
||||
tv_show_config_path,
|
||||
"sub",
|
||||
"--log-level",
|
||||
"verbose",
|
||||
"--match",
|
||||
"testA",
|
||||
"--match",
|
||||
"testB",
|
||||
],
|
||||
), patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=0),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"ytdl-sub",
|
||||
"-c",
|
||||
tv_show_config_path,
|
||||
"sub",
|
||||
"--log-level",
|
||||
"verbose",
|
||||
"--match",
|
||||
"testA",
|
||||
"--match",
|
||||
"testB",
|
||||
],
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_sub.call_count == 1
|
||||
|
|
@ -163,11 +182,15 @@ def test_sub_match_arguments_after_many(mock_sys_exit, tv_show_config_path):
|
|||
|
||||
|
||||
def test_no_config_works(mock_sys_exit):
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "sub", "--log-level", "verbose"],
|
||||
), patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=0),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "sub", "--log-level", "verbose"],
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_sub.call_count == 1
|
||||
|
|
@ -183,14 +206,19 @@ def test_uses_default_config_if_present(mock_sys_exit):
|
|||
open(DEFAULT_CONFIG_FILE_NAME, "a").close()
|
||||
|
||||
try:
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "sub", "--log-level", "verbose"],
|
||||
), patch(
|
||||
"ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files"
|
||||
) as mock_sub, patch.object(
|
||||
ConfigFile, "from_file_path", new=lambda _: ConfigFile(name="test default", value={})
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=0),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "sub", "--log-level", "verbose"],
|
||||
),
|
||||
patch("ytdl_sub.cli.entrypoint._download_subscriptions_from_yaml_files") as mock_sub,
|
||||
patch.object(
|
||||
ConfigFile,
|
||||
"from_file_path",
|
||||
new=lambda _: ConfigFile(name="test default", value={}),
|
||||
),
|
||||
):
|
||||
main()
|
||||
|
||||
|
|
@ -204,11 +232,15 @@ def test_uses_default_config_if_present(mock_sys_exit):
|
|||
|
||||
|
||||
def test_no_positional_arg_command(mock_sys_exit, tv_show_config_path):
|
||||
with mock_sys_exit(expected_exit_code=1), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", tv_show_config_path, "--log-level", "verbose"],
|
||||
), patch.object(logging.Logger, "error") as mock_error:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=1),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", tv_show_config_path, "--log-level", "verbose"],
|
||||
),
|
||||
patch.object(logging.Logger, "error") as mock_error,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_error.call_count == 1
|
||||
|
|
@ -216,11 +248,15 @@ def test_no_positional_arg_command(mock_sys_exit, tv_show_config_path):
|
|||
|
||||
|
||||
def test_bad_config_path(mock_sys_exit):
|
||||
with mock_sys_exit(expected_exit_code=1), patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", "does_not_exist.yaml", "sub", "--log-level", "verbose"],
|
||||
), patch.object(logging.Logger, "error") as mock_error:
|
||||
with (
|
||||
mock_sys_exit(expected_exit_code=1),
|
||||
patch.object(
|
||||
sys,
|
||||
"argv",
|
||||
["ytdl-sub", "-c", "does_not_exist.yaml", "sub", "--log-level", "verbose"],
|
||||
),
|
||||
patch.object(logging.Logger, "error") as mock_error,
|
||||
):
|
||||
main()
|
||||
|
||||
assert mock_error.call_count == 1
|
||||
|
|
|
|||
|
|
@ -39,23 +39,29 @@ class TestThrottleProtectionPlugin:
|
|||
preset_dict=preset_dict,
|
||||
)
|
||||
|
||||
with mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
), assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between downloads for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=4,
|
||||
with (
|
||||
mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
),
|
||||
assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between downloads for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=4,
|
||||
),
|
||||
):
|
||||
_ = subscription.download(dry_run=False)
|
||||
|
||||
with mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
), assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between subscriptions for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=1,
|
||||
with (
|
||||
mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
),
|
||||
assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between subscriptions for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=1,
|
||||
),
|
||||
):
|
||||
_ = subscription.download(dry_run=False)
|
||||
|
||||
|
|
@ -105,12 +111,15 @@ class TestThrottleProtectionPlugin:
|
|||
preset_dict=preset_dict,
|
||||
)
|
||||
|
||||
with mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
), assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between downloads for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=0,
|
||||
with (
|
||||
mock_download_collection_entries(
|
||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False
|
||||
),
|
||||
assert_logs(
|
||||
logger=throttle_protection_logger,
|
||||
expected_message="Sleeping between downloads for %0.2f seconds",
|
||||
log_level="debug",
|
||||
expected_occurrences=0,
|
||||
),
|
||||
):
|
||||
_ = subscription.download(dry_run=False)
|
||||
|
|
|
|||
Loading…
Reference in a new issue