From 9036ff860c2f4a66d5bcc71818fc4fa45f4e5e51 Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Thu, 19 Aug 2021 01:14:13 +0200 Subject: [PATCH] tests: look for sRGB.icc in several paths, skip related tests if not found --- src/img2pdf_test.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 33252c8..61504b8 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -20,6 +20,19 @@ import warnings import json 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 try: ver = subprocess.check_output(["mutool", "-v"], stderr=subprocess.STDOUT) @@ -304,11 +317,9 @@ def compare(im1, im2, exact, icc, cmyk): else: iccargs = [] if icc: - profile = "/usr/share/color/icc/sRGB.icc" - if not os.path.isfile(profile): - warnings.warn(profile + " not present, skipping checks...") - return - iccargs = ["-profile", profile] + if ICC_PROFILE is None: + pytest.skip("Could not locate an ICC profile") + iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( ["compare"] + iccargs @@ -421,10 +432,8 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): ) else: if icc: - profile = "/usr/share/color/icc/ghostscript/srgb.icc" - if not os.path.isfile(profile): - warnings.warn(profile + " not present, skipping checks...") - return + if ICC_PROFILE is None: + pytest.skip("Could not locate an ICC profile") psnr = subprocess.run( [ "compare", @@ -432,7 +441,7 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): "PSNR", "(", "-profile", - profile, + ICC_PROFILE, "-depth", "8", str(img),