tests: look for sRGB.icc in several paths, skip related tests if not found

This commit is contained in:
Louis Sautier 2021-08-19 01:14:13 +02:00
parent 1f3b456ac9
commit 9036ff860c
Signed by: sbraz
GPG key ID: A777716B30AE82E3

View file

@ -20,6 +20,19 @@ import warnings
import json import json
import pathlib import pathlib
SCRIPT_DIR = pathlib.Path(__file__).resolve().parent
ICC_PROFILE = None
ICC_PROFILE_PATHS = (
"/usr/share/color/icc/ghostscript/srgb.icc",
"/usr/share/ghostscript/9.54.0/iccprofiles/srgb.icc",
"/usr/share/color/icc/sRGB.icc",
"/usr/share/color/icc/OpenICC/sRGB.icc",
)
for path in ICC_PROFILE_PATHS:
if os.path.exists(path):
ICC_PROFILE = path
break
HAVE_MUTOOL = True HAVE_MUTOOL = True
try: try:
ver = subprocess.check_output(["mutool", "-v"], stderr=subprocess.STDOUT) ver = subprocess.check_output(["mutool", "-v"], stderr=subprocess.STDOUT)
@ -304,11 +317,9 @@ def compare(im1, im2, exact, icc, cmyk):
else: else:
iccargs = [] iccargs = []
if icc: if icc:
profile = "/usr/share/color/icc/sRGB.icc" if ICC_PROFILE is None:
if not os.path.isfile(profile): pytest.skip("Could not locate an ICC profile")
warnings.warn(profile + " not present, skipping checks...") iccargs = ["-profile", ICC_PROFILE]
return
iccargs = ["-profile", profile]
psnr = subprocess.run( psnr = subprocess.run(
["compare"] ["compare"]
+ iccargs + iccargs
@ -421,10 +432,8 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False):
) )
else: else:
if icc: if icc:
profile = "/usr/share/color/icc/ghostscript/srgb.icc" if ICC_PROFILE is None:
if not os.path.isfile(profile): pytest.skip("Could not locate an ICC profile")
warnings.warn(profile + " not present, skipping checks...")
return
psnr = subprocess.run( psnr = subprocess.run(
[ [
"compare", "compare",
@ -432,7 +441,7 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False):
"PSNR", "PSNR",
"(", "(",
"-profile", "-profile",
profile, ICC_PROFILE,
"-depth", "-depth",
"8", "8",
str(img), str(img),