From e15e49028b72546a1a2bf5a87fe11f56a4614f17 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 21 Dec 2021 21:03:33 -0700 Subject: [PATCH] Testing is_valid_poster --- modules/videos/common.py | 2 +- modules/videos/test/test_common.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/videos/common.py b/modules/videos/common.py index 5e800658..b01b3fe1 100644 --- a/modules/videos/common.py +++ b/modules/videos/common.py @@ -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) diff --git a/modules/videos/test/test_common.py b/modules/videos/test/test_common.py index d8369431..3d86c174 100644 --- a/modules/videos/test/test_common.py +++ b/modules/videos/test/test_common.py @@ -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', (