lint
This commit is contained in:
parent
551cba2beb
commit
2b9937f4dd
2 changed files with 52 additions and 50 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Any
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
@ -55,7 +56,7 @@ def mock_entry_dict_factory(mock_downloaded_file_path) -> Callable:
|
||||||
mock_download_to_working_dir: bool = True,
|
mock_download_to_working_dir: bool = True,
|
||||||
is_extracted_audio: bool = False,
|
is_extracted_audio: bool = False,
|
||||||
release_date: Optional[str] = None,
|
release_date: Optional[str] = None,
|
||||||
mock_entry_kwargs: Optional[Dict[str, Any]] = None
|
mock_entry_kwargs: Optional[Dict[str, Any]] = None,
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
entry_dict = {
|
entry_dict = {
|
||||||
v.uid.metadata_key: uid,
|
v.uid.metadata_key: uid,
|
||||||
|
|
@ -141,7 +142,9 @@ def mock_download_collection_thumbnail(mock_downloaded_file_path):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_download_collection_entries(
|
def mock_download_collection_entries(
|
||||||
mock_download_collection_thumbnail, mock_entry_dict_factory: Callable, working_directory: str,
|
mock_download_collection_thumbnail,
|
||||||
|
mock_entry_dict_factory: Callable,
|
||||||
|
working_directory: str,
|
||||||
):
|
):
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _mock_download_collection_entries_factory(
|
def _mock_download_collection_entries_factory(
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,7 @@ class TestThrottleProtectionPlugin:
|
||||||
|
|
||||||
assert transaction_log.is_empty
|
assert transaction_log.is_empty
|
||||||
|
|
||||||
|
|
||||||
class TestResolutionAssert:
|
class TestResolutionAssert:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"disable_value",
|
"disable_value",
|
||||||
|
|
@ -190,23 +191,21 @@ class TestResolutionAssert:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_disabled(
|
def test_disabled(
|
||||||
self,
|
self,
|
||||||
config,
|
config,
|
||||||
subscription_name,
|
subscription_name,
|
||||||
throttle_subscription_dict,
|
throttle_subscription_dict,
|
||||||
output_directory,
|
output_directory,
|
||||||
mock_download_collection_entries,
|
mock_download_collection_entries,
|
||||||
disable_value,
|
disable_value,
|
||||||
):
|
):
|
||||||
throttle_subscription_dict["overrides"]["enable_resolution_assert"] = disable_value
|
throttle_subscription_dict["overrides"]["enable_resolution_assert"] = disable_value
|
||||||
|
|
||||||
with (
|
with assert_logs(
|
||||||
assert_logs(
|
logger=script_print_logger,
|
||||||
logger=script_print_logger,
|
expected_message="Resolution assert is disabled. Use at your own risk!",
|
||||||
expected_message="Resolution assert is disabled. Use at your own risk!",
|
log_level="info",
|
||||||
log_level="info",
|
expected_occurrences=1,
|
||||||
expected_occurrences=1,
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
_ = Subscription.from_dict(
|
_ = Subscription.from_dict(
|
||||||
config=config,
|
config=config,
|
||||||
|
|
@ -222,25 +221,23 @@ class TestResolutionAssert:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_runs_successfully(
|
def test_runs_successfully(
|
||||||
self,
|
self,
|
||||||
config,
|
config,
|
||||||
subscription_name,
|
subscription_name,
|
||||||
throttle_subscription_dict,
|
throttle_subscription_dict,
|
||||||
output_directory,
|
output_directory,
|
||||||
mock_download_collection_entries,
|
mock_download_collection_entries,
|
||||||
width,
|
width,
|
||||||
height
|
height,
|
||||||
):
|
):
|
||||||
with (
|
with assert_logs(
|
||||||
assert_logs(
|
logger=script_print_logger,
|
||||||
logger=script_print_logger,
|
expected_message=(
|
||||||
expected_message=(
|
"Resolution assert is enabled, will fail on low-quality video downloads and presume throttle. "
|
||||||
"Resolution assert is enabled, will fail on low-quality video downloads and presume throttle. "
|
"Disable using the override variable `enable_resolution_assert: False`"
|
||||||
"Disable using the override variable `enable_resolution_assert: False`"
|
),
|
||||||
),
|
log_level="info",
|
||||||
log_level="info",
|
expected_occurrences=1,
|
||||||
expected_occurrences=1,
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
subscription = Subscription.from_dict(
|
subscription = Subscription.from_dict(
|
||||||
config=config,
|
config=config,
|
||||||
|
|
@ -250,21 +247,22 @@ class TestResolutionAssert:
|
||||||
|
|
||||||
with (
|
with (
|
||||||
mock_download_collection_entries(
|
mock_download_collection_entries(
|
||||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False, is_dry_run=True, mock_entry_kwargs={
|
is_youtube_channel=False,
|
||||||
"height": height,
|
num_urls=1,
|
||||||
"width": width
|
is_extracted_audio=False,
|
||||||
}
|
is_dry_run=True,
|
||||||
|
mock_entry_kwargs={"height": height, "width": width},
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
_ = subscription.download(dry_run=True)
|
_ = subscription.download(dry_run=True)
|
||||||
|
|
||||||
def test_fails_low_resolution(
|
def test_fails_low_resolution(
|
||||||
self,
|
self,
|
||||||
config,
|
config,
|
||||||
subscription_name,
|
subscription_name,
|
||||||
throttle_subscription_dict,
|
throttle_subscription_dict,
|
||||||
output_directory,
|
output_directory,
|
||||||
mock_download_collection_entries,
|
mock_download_collection_entries,
|
||||||
):
|
):
|
||||||
subscription = Subscription.from_dict(
|
subscription = Subscription.from_dict(
|
||||||
config=config,
|
config=config,
|
||||||
|
|
@ -279,11 +277,12 @@ class TestResolutionAssert:
|
||||||
|
|
||||||
with (
|
with (
|
||||||
mock_download_collection_entries(
|
mock_download_collection_entries(
|
||||||
is_youtube_channel=False, num_urls=1, is_extracted_audio=False, is_dry_run=True, mock_entry_kwargs={
|
is_youtube_channel=False,
|
||||||
"height": 360,
|
num_urls=1,
|
||||||
"width": 640
|
is_extracted_audio=False,
|
||||||
}
|
is_dry_run=True,
|
||||||
|
mock_entry_kwargs={"height": 360, "width": 640},
|
||||||
),
|
),
|
||||||
pytest.raises(UserThrownRuntimeError, match=re.escape(expected_message)),
|
pytest.raises(UserThrownRuntimeError, match=re.escape(expected_message)),
|
||||||
):
|
):
|
||||||
_ = subscription.download(dry_run=True)
|
_ = subscription.download(dry_run=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue