TestSuite: Add support for GraphicsMagick

Add support to run the tests using GraphicsMagick's "gm convert" instead
of ImageMagick's "convert".
This commit is contained in:
Latosha Maltba 2021-03-21 14:36:18 +00:00
parent 7ab8ec9b91
commit ef864d72f1
2 changed files with 27 additions and 9 deletions

View File

@ -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:

View File

@ -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)