test
This commit is contained in:
parent
9fd46bf929
commit
43ceea9b54
3 changed files with 46 additions and 8 deletions
|
|
@ -106,7 +106,7 @@ class OutputOptions(OptionsDictValidator):
|
||||||
"keep_files_after",
|
"keep_files_after",
|
||||||
"keep_max_files",
|
"keep_max_files",
|
||||||
"download_archive_standardized_date",
|
"download_archive_standardized_date",
|
||||||
"entry_date_eval",
|
"keep_files_date_eval",
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -164,10 +164,10 @@ class OutputOptions(OptionsDictValidator):
|
||||||
self._keep_max_files = self._validate_key_if_present(
|
self._keep_max_files = self._validate_key_if_present(
|
||||||
"keep_max_files", OverridesIntegerFormatterValidator
|
"keep_max_files", OverridesIntegerFormatterValidator
|
||||||
)
|
)
|
||||||
self._entry_date_eval = self._validate_key(
|
self._keep_files_date_eval = self._validate_key(
|
||||||
"entry_date_eval",
|
"keep_files_date_eval",
|
||||||
StandardizedDateValidator,
|
StandardizedDateValidator,
|
||||||
default=f"{{{v.upload_date_standardized.variable_name}}}"
|
default=f"{{{v.upload_date_standardized.variable_name}}}",
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
@ -286,7 +286,7 @@ class OutputOptions(OptionsDictValidator):
|
||||||
return self._keep_files_after
|
return self._keep_files_after
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entry_date_eval(self) -> StandardizedDateValidator:
|
def keep_files_date_eval(self) -> StandardizedDateValidator:
|
||||||
"""
|
"""
|
||||||
:expected type: str
|
:expected type: str
|
||||||
:description:
|
:description:
|
||||||
|
|
@ -295,7 +295,7 @@ class OutputOptions(OptionsDictValidator):
|
||||||
perform evaluation for keep_files_before/after and keep_max_files. Defaults
|
perform evaluation for keep_files_before/after and keep_max_files. Defaults
|
||||||
to the entry's upload_date_standardized variable.
|
to the entry's upload_date_standardized variable.
|
||||||
"""
|
"""
|
||||||
return self._entry_date_eval
|
return self._keep_files_date_eval
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def keep_max_files(self) -> Optional[OverridesIntegerFormatterValidator]:
|
def keep_max_files(self) -> Optional[OverridesIntegerFormatterValidator]:
|
||||||
|
|
|
||||||
|
|
@ -221,12 +221,16 @@ class SubscriptionDownload(BaseSubscription, ABC):
|
||||||
|
|
||||||
# Inject OutputOption variables here
|
# Inject OutputOption variables here
|
||||||
entry.add(
|
entry.add(
|
||||||
{VARIABLES.ytdl_sub_entry_date_eval: self.output_options.entry_date_eval.format_string}
|
{
|
||||||
|
VARIABLES.ytdl_sub_entry_date_eval: (
|
||||||
|
self.output_options.keep_files_date_eval.format_string
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Run it to make sure it's actually a standardized date
|
# Run it to make sure it's actually a standardized date
|
||||||
_ = self.overrides.apply_formatter(
|
_ = self.overrides.apply_formatter(
|
||||||
formatter=self.output_options.entry_date_eval, entry=entry
|
formatter=self.output_options.keep_files_date_eval, entry=entry
|
||||||
)
|
)
|
||||||
|
|
||||||
for plugin in PluginMapping.order_plugins_by(
|
for plugin in PluginMapping.order_plugins_by(
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
@ -11,6 +12,7 @@ from ytdl_sub.config.config_file import ConfigFile
|
||||||
from ytdl_sub.downloaders.ytdlp import YTDLP
|
from ytdl_sub.downloaders.ytdlp import YTDLP
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
|
from ytdl_sub.utils.exceptions import ValidationException
|
||||||
from ytdl_sub.utils.file_handler import FileHandler
|
from ytdl_sub.utils.file_handler import FileHandler
|
||||||
from ytdl_sub.utils.thumbnail import try_convert_download_thumbnail
|
from ytdl_sub.utils.thumbnail import try_convert_download_thumbnail
|
||||||
|
|
||||||
|
|
@ -223,3 +225,35 @@ class TestOutputOptions:
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
expected_download_summary_file_name="plugins/output_options/test_missing_thumb.json",
|
expected_download_summary_file_name="plugins/output_options/test_missing_thumb.json",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_invalid_keep_files_date_eval(
|
||||||
|
self,
|
||||||
|
config: ConfigFile,
|
||||||
|
subscription_name: str,
|
||||||
|
output_options_subscription_dict: Dict,
|
||||||
|
output_directory: str,
|
||||||
|
mock_download_collection_entries,
|
||||||
|
):
|
||||||
|
output_options_subscription_dict["output_options"]["keep_files_date_eval"] = "nope"
|
||||||
|
|
||||||
|
subscription = Subscription.from_dict(
|
||||||
|
config=config,
|
||||||
|
preset_name=subscription_name,
|
||||||
|
preset_dict=output_options_subscription_dict,
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_error_msg = (
|
||||||
|
"Validation error in subscription_test.output_options.keep_files_date_eval: "
|
||||||
|
"Expected a standardized date in the form of YYYY-MM-DD, but received 'nope'"
|
||||||
|
)
|
||||||
|
|
||||||
|
with (
|
||||||
|
mock_download_collection_entries(
|
||||||
|
is_youtube_channel=False,
|
||||||
|
num_urls=1,
|
||||||
|
is_extracted_audio=False,
|
||||||
|
is_dry_run=True,
|
||||||
|
),
|
||||||
|
pytest.raises(ValidationException, match=re.escape(expected_error_msg)),
|
||||||
|
):
|
||||||
|
subscription.download(dry_run=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue