Skip to content

Commit

Permalink
Drop use of deprecated imghdr standard library module
Browse files Browse the repository at this point in the history
which has been removed in the upcoming Python 3.13 .
  • Loading branch information
nsoranzo committed Sep 5, 2024
1 parent 97a126d commit 651613c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 0 additions & 5 deletions lib/galaxy/util/image_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides utilities for working with image files."""

import imghdr
import logging
from typing import (
List,
Expand All @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion test/unit/util/test_checkers.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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

0 comments on commit 651613c

Please sign in to comment.