diff --git a/Tests/helper.py b/Tests/helper.py index be3bdb76f..5573c78c4 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -257,8 +257,16 @@ def netpbm_available(): return bool(shutil.which("ppmquant") and shutil.which("ppmtogif")) +def convert_available(): + return imagemagick_available() or graphicsmagick_available() + + def imagemagick_available(): - return bool(IMCONVERT and shutil.which(IMCONVERT)) + return bool(IMCONVERT and shutil.which(IMCONVERT[0])) + + +def graphicsmagick_available(): + return bool(GMCONVERT and shutil.which(GMCONVERT[0])) def on_appveyor(): @@ -298,10 +306,20 @@ def is_mingw(): if sys.platform == "win32": IMCONVERT = os.environ.get("MAGICK_HOME", "") + GMCONVERT = None if IMCONVERT: - IMCONVERT = os.path.join(IMCONVERT, "convert.exe") + IMCONVERT = [os.path.join(IMCONVERT, "convert.exe")] + GMCONVERT = [os.path.join(IMCONVERT, "gm.exe"), "convert"] else: - IMCONVERT = "convert" + IMCONVERT = ["convert"] + GMCONVERT = ["gm", "convert"] + +if imagemagick_available(): + CONVERT = IMCONVERT +elif graphicsmagick_available(): + CONVERT = GMCONVERT +else: + CONVERT = None class cached_property: diff --git a/Tests/test_file_palm.py b/Tests/test_file_palm.py index 25d194b62..bbbab25d8 100644 --- a/Tests/test_file_palm.py +++ b/Tests/test_file_palm.py @@ -5,9 +5,9 @@ import pytest from PIL import Image -from .helper import IMCONVERT, assert_image_equal, hopper, imagemagick_available +from .helper import CONVERT, assert_image_equal, convert_available, hopper -_roundtrip = imagemagick_available() +_roundtrip = convert_available() def helper_save_as_palm(tmp_path, mode): @@ -23,13 +23,13 @@ def helper_save_as_palm(tmp_path, mode): assert os.path.getsize(outfile) > 0 -def open_with_imagemagick(tmp_path, f): - if not imagemagick_available(): +def open_with_convert(tmp_path, f): + if not convert_available(): raise OSError() outfile = str(tmp_path / "temp.png") rc = subprocess.call( - [IMCONVERT, f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT + CONVERT + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT ) if rc: raise OSError @@ -44,7 +44,7 @@ def roundtrip(tmp_path, mode): outfile = str(tmp_path / "temp.palm") im.save(outfile) - converted = open_with_imagemagick(tmp_path, outfile) + converted = open_with_convert(tmp_path, outfile) assert_image_equal(converted, im)