fix test
This commit is contained in:
parent
3471d7089e
commit
df712750cd
3 changed files with 15 additions and 9 deletions
|
|
@ -228,7 +228,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions
|
||||||
self,
|
self,
|
||||||
thumbnail_url: str,
|
thumbnail_url: str,
|
||||||
output_thumbnail_path: str,
|
output_thumbnail_path: str,
|
||||||
):
|
) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
Downloads a thumbnail and stores it in the output directory
|
Downloads a thumbnail and stores it in the output directory
|
||||||
|
|
||||||
|
|
@ -238,12 +238,16 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions
|
||||||
Url of the thumbnail
|
Url of the thumbnail
|
||||||
output_thumbnail_path:
|
output_thumbnail_path:
|
||||||
Path to store the thumbnail after downloading
|
Path to store the thumbnail after downloading
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
True if the thumbnail converted. None if it is missing or failed.
|
||||||
"""
|
"""
|
||||||
if not thumbnail_url:
|
if not thumbnail_url:
|
||||||
download_logger.warning("Could not find a thumbnail for %s", self.channel.uid)
|
download_logger.warning("Could not find a thumbnail for %s", self.channel.uid)
|
||||||
return
|
return None
|
||||||
|
|
||||||
convert_url_thumbnail(
|
return convert_url_thumbnail(
|
||||||
thumbnail_url=thumbnail_url, output_thumbnail_path=output_thumbnail_path
|
thumbnail_url=thumbnail_url, output_thumbnail_path=output_thumbnail_path
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from typing import Optional
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
|
|
@ -34,7 +35,7 @@ def convert_download_thumbnail(entry: Entry, error_if_not_found: bool = True) ->
|
||||||
|
|
||||||
|
|
||||||
@retry(times=5, exceptions=(Exception,))
|
@retry(times=5, exceptions=(Exception,))
|
||||||
def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> bool:
|
def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
Downloads and converts a thumbnail from a url into a jpg
|
Downloads and converts a thumbnail from a url into a jpg
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> boo
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
True to indicate it converted the thumbnail from url
|
True to indicate it converted the thumbnail from url. None if the retry failed.
|
||||||
"""
|
"""
|
||||||
with urlopen(thumbnail_url) as file:
|
with urlopen(thumbnail_url) as file:
|
||||||
with tempfile.NamedTemporaryFile() as thumbnail:
|
with tempfile.NamedTemporaryFile() as thumbnail:
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,13 @@ class TestChannelAsKodiTvShow:
|
||||||
config=channel_as_tv_show_config, preset_name="pz", preset_dict=channel_preset_dict
|
config=channel_as_tv_show_config, preset_name="pz", preset_dict=channel_preset_dict
|
||||||
)
|
)
|
||||||
|
|
||||||
with assert_debug_log(
|
with assert_debug_log( # Ensure retry debug message is thrown
|
||||||
logger=retry_logger,
|
logger=retry_logger,
|
||||||
expected_message="Exception thrown when attempting to run convert_url_thumbnail, attempt 5 of 5",
|
expected_message="Exception thrown when attempting to run %s, attempt %d of %d",
|
||||||
), patch("ytdl_sub.utils.retry.sleep"), patch(
|
), patch( # Make sleeps instant
|
||||||
|
"ytdl_sub.utils.retry.sleep"
|
||||||
|
), patch( # Mock error when calling urlopen
|
||||||
"ytdl_sub.utils.thumbnail.urlopen"
|
"ytdl_sub.utils.thumbnail.urlopen"
|
||||||
) as mock_urlopen:
|
) as mock_urlopen:
|
||||||
mock_urlopen.side_effect = [Exception("error")]
|
mock_urlopen.side_effect = [Exception("error")]
|
||||||
|
|
||||||
full_channel_subscription.download(dry_run=True)
|
full_channel_subscription.download(dry_run=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue