mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
Testing is_valid_poster
This commit is contained in:
parent
9d74b24f2b
commit
e15e49028b
2 changed files with 19 additions and 2 deletions
|
|
@ -366,7 +366,7 @@ def convert_image(existing_path: Path, destination_path: Path, ext: str = 'jpeg'
|
|||
|
||||
|
||||
def is_valid_poster(poster_path: Path) -> bool:
|
||||
"""Return True only if poster file exists, and is of a JPEG format."""
|
||||
"""Return True only if poster file exists, and is a JPEG format."""
|
||||
if poster_path.is_file():
|
||||
try:
|
||||
img = Image.open(poster_path)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from wrolpi.db import get_db_session
|
|||
from wrolpi.test.common import build_test_directories, wrap_test_db, TestAPI
|
||||
from wrolpi.vars import PROJECT_DIR
|
||||
from ..common import get_matching_directories, convert_image, bulk_validate_posters, remove_duplicate_video_paths, \
|
||||
update_view_count, get_video_duration, generate_video_poster, replace_extension
|
||||
update_view_count, get_video_duration, generate_video_poster, replace_extension, is_valid_poster
|
||||
|
||||
|
||||
class TestCommon(TestAPI):
|
||||
|
|
@ -110,6 +110,23 @@ def test_convert_image():
|
|||
assert Image.open(destination_path).format == 'JPEG'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'ext,expected',
|
||||
[
|
||||
('jpg', True),
|
||||
('jpeg', True),
|
||||
('png', False),
|
||||
('webp', False),
|
||||
('tif', False),
|
||||
]
|
||||
)
|
||||
def test_is_valid_poster(ext, expected, test_directory):
|
||||
foo = Image.new('RGB', (25, 25), color='blue')
|
||||
image_path = test_directory / f'image.{ext}'
|
||||
foo.save(image_path)
|
||||
assert is_valid_poster(image_path) == expected, f'is_valid_poster({image_path}) should be {expected}'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'_structure,paths',
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue