diff --git a/lib/galaxy/util/image_util.py b/lib/galaxy/util/image_util.py index 3b11a50d2fda..b8c26cf0ff54 100644 --- a/lib/galaxy/util/image_util.py +++ b/lib/galaxy/util/image_util.py @@ -1,6 +1,5 @@ """Provides utilities for working with image files.""" -import imghdr import logging from typing import ( List, @@ -22,11 +21,7 @@ def image_type(filename: str) -> Optional[str]: with Image.open(filename) as im: fmt = im.format except Exception: - # We continue to try with imghdr, so this is a rare case of an - # exception we expect to happen frequently, so we're not logging pass - if not fmt: - fmt = imghdr.what(filename) if fmt: return fmt.upper() else: diff --git a/test/unit/util/test_checkers.py b/test/unit/util/test_checkers.py index 1e30d25656cd..b474defc965a 100644 --- a/test/unit/util/test_checkers.py +++ b/test/unit/util/test_checkers.py @@ -1,6 +1,10 @@ +import os.path import tempfile -from galaxy.util.checkers import check_html +from galaxy.util.checkers import ( + check_html, + check_image, +) def test_check_html(): @@ -17,3 +21,10 @@ def test_check_html(): tmpb.write(b"\x1f\x8b") tmpb.flush() assert not check_html(tmpb.name) + + +def test_check_image(): + for filename, expected in (("1.tiff", True), ("454Score.png", True), ("1.bam", False)): + path = f"test-data/{filename}" + assert os.path.exists(path) + assert check_image(path) is expected