Many tests failing with imagemagick 7.1.0-48 #148

Closed
opened 2022-09-15 00:08:58 +00:00 by hexa · 8 comments

We recently upgraded imagemagick in NixOS unstable from 7.1.0-47 to 7.1.0-48 and img2pdf 0.4.4 has multiple tests failing in the same way.

============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
rootdir: /build/img2pdf-0.4.4
collected 301 items / 12 deselected / 289 selected                             

src/img2pdf_test.py ....FFss..FF..................FF........ss.......... [ 17%]
....FF.................................................................. [ 42%]
........................................................................ [ 67%]
........................................................................ [ 92%]
.....................                                                    [100%]

=================================== FAILURES ===================================
___________________________ test_jpg_cmyk[internal] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
>       compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5330: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b' (0)'

src/img2pdf_test.py:348: ValueError
____________________________ test_jpg_cmyk[pikepdf] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
>       compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5330: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b' (0)'

src/img2pdf_test.py:348: ValueError
___________________________ test_png_rgb16[internal] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
png_rgb16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png')
png_rgb16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_rgb16_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_png_rgb16(tmp_path_factory, png_rgb16_img, png_rgb16_pdf):
        tmpdir = tmp_path_factory.mktemp("png_rgb16")
        compare_ghostscript(tmpdir, png_rgb16_img, png_rgb16_pdf, gsdevice="tiff48nc")
        # poppler outputs 8-bit RGB so the comparison will not be exact
>       compare_poppler(tmpdir, png_rgb16_img, png_rgb16_pdf, exact=False)

src/img2pdf_test.py:5373: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:380: in compare_poppler
    compare(str(img), str(tmpdir / "poppler-1.png"), exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png'
im2 = '/build/pytest-of-nixbld/pytest-0/png_rgb160/poppler-1.png', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b'60.5175 (0.605175)'

src/img2pdf_test.py:348: ValueError
----------------------------- Captured stderr call -----------------------------
0
___________________________ test_png_rgb16[pikepdf] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
png_rgb16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png')
png_rgb16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_rgb16_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_png_rgb16(tmp_path_factory, png_rgb16_img, png_rgb16_pdf):
        tmpdir = tmp_path_factory.mktemp("png_rgb16")
        compare_ghostscript(tmpdir, png_rgb16_img, png_rgb16_pdf, gsdevice="tiff48nc")
        # poppler outputs 8-bit RGB so the comparison will not be exact
>       compare_poppler(tmpdir, png_rgb16_img, png_rgb16_pdf, exact=False)

src/img2pdf_test.py:5373: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:380: in compare_poppler
    compare(str(img), str(tmpdir / "poppler-1.png"), exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png'
im2 = '/build/pytest-of-nixbld/pytest-0/png_rgb161/poppler-1.png', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b'60.5175 (0.605175)'

src/img2pdf_test.py:348: ValueError
----------------------------- Captured stderr call -----------------------------
0
__________________________ test_png_gray16[internal] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
png_gray16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png')
png_gray16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_gray16_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_png_gray16(tmp_path_factory, png_gray16_img, png_gray16_pdf):
        tmpdir = tmp_path_factory.mktemp("png_gray16")
        # ghostscript outputs 8-bit grayscale, so the comparison will not be exact
>       compare_ghostscript(
            tmpdir, png_gray16_img, png_gray16_pdf, gsdevice="pnggray", exact=False
        )

src/img2pdf_test.py:5508: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png'
im2 = '/build/pytest-of-nixbld/pytest-0/png_gray160/gs-1.png', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b'60.549 (0.60549)'

src/img2pdf_test.py:348: ValueError
___________________________ test_png_gray16[pikepdf] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
png_gray16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png')
png_gray16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_gray16_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_png_gray16(tmp_path_factory, png_gray16_img, png_gray16_pdf):
        tmpdir = tmp_path_factory.mktemp("png_gray16")
        # ghostscript outputs 8-bit grayscale, so the comparison will not be exact
>       compare_ghostscript(
            tmpdir, png_gray16_img, png_gray16_pdf, gsdevice="pnggray", exact=False
        )

src/img2pdf_test.py:5508: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png'
im2 = '/build/pytest-of-nixbld/pytest-0/png_gray161/gs-1.png', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b'60.549 (0.60549)'

src/img2pdf_test.py:348: ValueError
__________________________ test_tiff_cmyk8[internal] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
>       compare_ghostscript(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5687: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b' (0)'

src/img2pdf_test.py:348: ValueError
___________________________ test_tiff_cmyk8[pikepdf] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
>       compare_ghostscript(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5687: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:372: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           psnr = float(psnr.strip(b"0"))
E           ValueError: could not convert string to float: b' (0)'

src/img2pdf_test.py:348: ValueError
=============================== warnings summary ===============================
src/img2pdf_test.py:114
  /build/img2pdf-0.4.4/src/img2pdf_test.py:114: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks...
    warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - ValueError: could not c...
FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - ValueError: could not co...
FAILED src/img2pdf_test.py::test_png_rgb16[internal] - ValueError: could not ...
FAILED src/img2pdf_test.py::test_png_rgb16[pikepdf] - ValueError: could not c...
FAILED src/img2pdf_test.py::test_png_gray16[internal] - ValueError: could not...
FAILED src/img2pdf_test.py::test_png_gray16[pikepdf] - ValueError: could not ...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - ValueError: could not...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - ValueError: could not ...
===== 8 failed, 277 passed, 4 skipped, 12 deselected, 1 warning in 38.26s ======
We recently upgraded imagemagick in NixOS unstable from 7.1.0-47 to 7.1.0-48 and img2pdf 0.4.4 has multiple tests failing in the same way. ``` ============================= test session starts ============================== platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0 rootdir: /build/img2pdf-0.4.4 collected 301 items / 12 deselected / 289 selected src/img2pdf_test.py ....FFss..FF..................FF........ss.......... [ 17%] ....FF.................................................................. [ 42%] ........................................................................ [ 67%] ........................................................................ [ 92%] ..................... [100%] =================================== FAILURES =================================== ___________________________ test_jpg_cmyk[internal] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") > compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5330: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b' (0)' src/img2pdf_test.py:348: ValueError ____________________________ test_jpg_cmyk[pikepdf] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") > compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5330: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b' (0)' src/img2pdf_test.py:348: ValueError ___________________________ test_png_rgb16[internal] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) png_rgb16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png') png_rgb16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_rgb16_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_png_rgb16(tmp_path_factory, png_rgb16_img, png_rgb16_pdf): tmpdir = tmp_path_factory.mktemp("png_rgb16") compare_ghostscript(tmpdir, png_rgb16_img, png_rgb16_pdf, gsdevice="tiff48nc") # poppler outputs 8-bit RGB so the comparison will not be exact > compare_poppler(tmpdir, png_rgb16_img, png_rgb16_pdf, exact=False) src/img2pdf_test.py:5373: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:380: in compare_poppler compare(str(img), str(tmpdir / "poppler-1.png"), exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png' im2 = '/build/pytest-of-nixbld/pytest-0/png_rgb160/poppler-1.png', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b'60.5175 (0.605175)' src/img2pdf_test.py:348: ValueError ----------------------------- Captured stderr call ----------------------------- 0 ___________________________ test_png_rgb16[pikepdf] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) png_rgb16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png') png_rgb16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_rgb16_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_png_rgb16(tmp_path_factory, png_rgb16_img, png_rgb16_pdf): tmpdir = tmp_path_factory.mktemp("png_rgb16") compare_ghostscript(tmpdir, png_rgb16_img, png_rgb16_pdf, gsdevice="tiff48nc") # poppler outputs 8-bit RGB so the comparison will not be exact > compare_poppler(tmpdir, png_rgb16_img, png_rgb16_pdf, exact=False) src/img2pdf_test.py:5373: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:380: in compare_poppler compare(str(img), str(tmpdir / "poppler-1.png"), exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/normal16_png0/normal16.png' im2 = '/build/pytest-of-nixbld/pytest-0/png_rgb161/poppler-1.png', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b'60.5175 (0.605175)' src/img2pdf_test.py:348: ValueError ----------------------------- Captured stderr call ----------------------------- 0 __________________________ test_png_gray16[internal] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) png_gray16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png') png_gray16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_gray16_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_png_gray16(tmp_path_factory, png_gray16_img, png_gray16_pdf): tmpdir = tmp_path_factory.mktemp("png_gray16") # ghostscript outputs 8-bit grayscale, so the comparison will not be exact > compare_ghostscript( tmpdir, png_gray16_img, png_gray16_pdf, gsdevice="pnggray", exact=False ) src/img2pdf_test.py:5508: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png' im2 = '/build/pytest-of-nixbld/pytest-0/png_gray160/gs-1.png', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b'60.549 (0.60549)' src/img2pdf_test.py:348: ValueError ___________________________ test_png_gray16[pikepdf] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) png_gray16_img = PosixPath('/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png') png_gray16_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/png_gray16_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_png_gray16(tmp_path_factory, png_gray16_img, png_gray16_pdf): tmpdir = tmp_path_factory.mktemp("png_gray16") # ghostscript outputs 8-bit grayscale, so the comparison will not be exact > compare_ghostscript( tmpdir, png_gray16_img, png_gray16_pdf, gsdevice="pnggray", exact=False ) src/img2pdf_test.py:5508: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/gray16_png0/gray16.png' im2 = '/build/pytest-of-nixbld/pytest-0/png_gray161/gs-1.png', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b'60.549 (0.60549)' src/img2pdf_test.py:348: ValueError __________________________ test_tiff_cmyk8[internal] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") > compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5687: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b' (0)' src/img2pdf_test.py:348: ValueError ___________________________ test_tiff_cmyk8[pikepdf] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") > compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5687: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:372: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > psnr = float(psnr.strip(b"0")) E ValueError: could not convert string to float: b' (0)' src/img2pdf_test.py:348: ValueError =============================== warnings summary =============================== src/img2pdf_test.py:114 /build/img2pdf-0.4.4/src/img2pdf_test.py:114: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks... warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - ValueError: could not c... FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - ValueError: could not co... FAILED src/img2pdf_test.py::test_png_rgb16[internal] - ValueError: could not ... FAILED src/img2pdf_test.py::test_png_rgb16[pikepdf] - ValueError: could not c... FAILED src/img2pdf_test.py::test_png_gray16[internal] - ValueError: could not... FAILED src/img2pdf_test.py::test_png_gray16[pikepdf] - ValueError: could not ... FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - ValueError: could not... FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - ValueError: could not ... ===== 8 failed, 277 passed, 4 skipped, 12 deselected, 1 warning in 38.26s ====== ```
Owner

I suspect that this is the culprit:

751829cd4c

Can you confirm if the following (untested) diff fixes the problem?

diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py
index 31b4043..f11df03 100755
--- a/src/img2pdf_test.py
+++ b/src/img2pdf_test.py
@@ -113,6 +113,12 @@ except subprocess.CalledProcessError:
 if not HAVE_JP2:
     warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")
 
+# the result of compare -metric PSNR is either just a floating point value or a
+# floating point value following by the same value multiplied by 0.01,
+# surrounded in parenthesis since ImagemMagick 7.1.0-48:
+# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f
+psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]+)(?:.[0-9]+)?))(?: \([0-9.]+\))?")
+
 ###############################################################################
 #                               HELPER FUNCTIONS                              #
 ###############################################################################
@@ -345,7 +351,10 @@ def compare(im1, im2, exact, icc, cmyk):
             stderr=subprocess.PIPE,
         ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        assert psnr_re.fullmatch(psnr) is not None, psnr
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
 
@@ -501,7 +510,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False):
                 stderr=subprocess.PIPE,
             ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
     (tmpdir / "images-000.png").unlink()
I suspect that this is the culprit: https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f Can you confirm if the following (untested) diff fixes the problem? ```patch diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 31b4043..f11df03 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -113,6 +113,12 @@ except subprocess.CalledProcessError: if not HAVE_JP2: warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") +# the result of compare -metric PSNR is either just a floating point value or a +# floating point value following by the same value multiplied by 0.01, +# surrounded in parenthesis since ImagemMagick 7.1.0-48: +# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f +psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]+)(?:.[0-9]+)?))(?: \([0-9.]+\))?") + ############################################################################### # HELPER FUNCTIONS # ############################################################################### @@ -345,7 +351,10 @@ def compare(im1, im2, exact, icc, cmyk): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + assert psnr_re.fullmatch(psnr) is not None, psnr + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 @@ -501,7 +510,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 (tmpdir / "images-000.png").unlink() ```
Author

With that patch applied we arrive here:

============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
rootdir: /build/img2pdf-0.4.4
collected 301 items / 12 deselected / 289 selected                             

src/img2pdf_test.py ....FFss................................ss.......... [ 17%]
....FF.................................................................. [ 42%]
........................................................................ [ 67%]
........................................................................ [ 92%]
.....................                                                    [100%]

=================================== FAILURES ===================================
___________________________ test_jpg_cmyk[internal] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
>       compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/img2pdf_test.py:381: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           assert psnr != b"0 (0)"
E           AssertionError: assert b'0 (0)' != b'0 (0)'

src/img2pdf_test.py:354: AssertionError
____________________________ test_jpg_cmyk[pikepdf] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
>       compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/img2pdf_test.py:381: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           assert psnr != b"0 (0)"
E           AssertionError: assert b'0 (0)' != b'0 (0)'

src/img2pdf_test.py:354: AssertionError
__________________________ test_tiff_cmyk8[internal] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
>       compare_ghostscript(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/img2pdf_test.py:381: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           assert psnr != b"0 (0)"
E           AssertionError: assert b'0 (0)' != b'0 (0)'

src/img2pdf_test.py:354: AssertionError
___________________________ test_tiff_cmyk8[pikepdf] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
>       compare_ghostscript(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
        )

src/img2pdf_test.py:5698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/img2pdf_test.py:381: in compare_ghostscript
    compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/gs-1.tiff', exact = False
icc = False, cmyk = False

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
                raise Exception("cmyk cannot be exact")
            elif icc:
                raise Exception("icc cannot be exact")
            else:
                subprocess.check_call(
                    COMPARE
                    + [
                        "-metric",
                        "AE",
                        im1,
                        im2,
                        "null:",
                    ]
                )
        else:
            iccargs = []
            if icc:
                if ICC_PROFILE is None:
                    pytest.skip("Could not locate an ICC profile")
                iccargs = ["-profile", ICC_PROFILE]
            psnr = subprocess.run(
                COMPARE
                + iccargs
                + [
                    "-metric",
                    "PSNR",
                    im1,
                    im2,
                    "null:",
                ],
                check=False,
                stderr=subprocess.PIPE,
            ).stderr
            assert psnr != b"0"
>           assert psnr != b"0 (0)"
E           AssertionError: assert b'0 (0)' != b'0 (0)'

src/img2pdf_test.py:354: AssertionError
=============================== warnings summary ===============================
src/img2pdf_test.py:114
  /build/img2pdf-0.4.4/src/img2pdf_test.py:114: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks...
    warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - AssertionError: assert ...
FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - AssertionError: assert b...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - AssertionError: asser...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - AssertionError: assert...
= 4 failed, 281 passed, 4 skipped, 12 deselected, 1 warning in 103.72s (0:01:43) =
With that patch applied we arrive here: ``` ============================= test session starts ============================== platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0 rootdir: /build/img2pdf-0.4.4 collected 301 items / 12 deselected / 289 selected src/img2pdf_test.py ....FFss................................ss.......... [ 17%] ....FF.................................................................. [ 42%] ........................................................................ [ 67%] ........................................................................ [ 92%] ..................... [100%] =================================== FAILURES =================================== ___________________________ test_jpg_cmyk[internal] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") > compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5341: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:381: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > assert psnr != b"0 (0)" E AssertionError: assert b'0 (0)' != b'0 (0)' src/img2pdf_test.py:354: AssertionError ____________________________ test_jpg_cmyk[pikepdf] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") > compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5341: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:381: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > assert psnr != b"0 (0)" E AssertionError: assert b'0 (0)' != b'0 (0)' src/img2pdf_test.py:354: AssertionError __________________________ test_tiff_cmyk8[internal] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") > compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5698: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:381: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > assert psnr != b"0 (0)" E AssertionError: assert b'0 (0)' != b'0 (0)' src/img2pdf_test.py:354: AssertionError ___________________________ test_tiff_cmyk8[pikepdf] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") > compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False ) src/img2pdf_test.py:5698: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:381: in compare_ghostscript compare(str(img), str(tmpdir / "gs-1.") + ext, exact, icc, False) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/gs-1.tiff', exact = False icc = False, cmyk = False def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: raise Exception("cmyk cannot be exact") elif icc: raise Exception("icc cannot be exact") else: subprocess.check_call( COMPARE + [ "-metric", "AE", im1, im2, "null:", ] ) else: iccargs = [] if icc: if ICC_PROFILE is None: pytest.skip("Could not locate an ICC profile") iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( COMPARE + iccargs + [ "-metric", "PSNR", im1, im2, "null:", ], check=False, stderr=subprocess.PIPE, ).stderr assert psnr != b"0" > assert psnr != b"0 (0)" E AssertionError: assert b'0 (0)' != b'0 (0)' src/img2pdf_test.py:354: AssertionError =============================== warnings summary =============================== src/img2pdf_test.py:114 /build/img2pdf-0.4.4/src/img2pdf_test.py:114: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks... warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - AssertionError: assert ... FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - AssertionError: assert b... FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - AssertionError: asser... FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - AssertionError: assert... = 4 failed, 281 passed, 4 skipped, 12 deselected, 1 warning in 103.72s (0:01:43) = ```
Owner

Oh wow, that imagemagick release is wild! I think that this commit might've fixed the in-exact cmyk issues: c1ca247654

Can you try this new patch?

diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py
index 31b4043..72e67c4 100755
--- a/src/img2pdf_test.py
+++ b/src/img2pdf_test.py
@@ -75,6 +75,7 @@ for prog in ["convert", "compare", "identify"]:
         globals()[prog.upper()] = ["magick", prog]
 
 HAVE_IMAGEMAGICK_MODERN = True
+HAVE_EXACT_CMYK8 = True
 try:
     ver = subprocess.check_output(CONVERT + ["-version"], stderr=subprocess.STDOUT)
     m = re.fullmatch(
@@ -82,13 +83,18 @@ try:
     )
     if m is None:
         HAVE_IMAGEMAGICK_MODERN = False
+        HAVE_EXACT_CMYK8 = False
     else:
         if parse_version(m.group(1)) < parse_version("6.9.10-12"):
             HAVE_IMAGEMAGICK_MODERN = False
+        if parse_version(m.group(1)) < parse_version("7.1.0-48"):
+            HAVE_EXACT_CMYK8 = False
 except FileNotFoundError:
     HAVE_IMAGEMAGICK_MODERN = False
+    HAVE_EXACT_CMYK8 = False
 except subprocess.CalledProcessError:
     HAVE_IMAGEMAGICK_MODERN = False
+    HAVE_EXACT_CMYK8 = False
 
 if not HAVE_IMAGEMAGICK_MODERN:
     warnings.warn("imagemagick >= 6.9.10-12 not available, skipping certain checks...")
@@ -113,6 +119,12 @@ except subprocess.CalledProcessError:
 if not HAVE_JP2:
     warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")
 
+# the result of compare -metric PSNR is either just a floating point value or a
+# floating point value following by the same value multiplied by 0.01,
+# surrounded in parenthesis since ImagemMagick 7.1.0-48:
+# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f
+psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?))(?: \([0-9.]+\))?")
+
 ###############################################################################
 #                               HELPER FUNCTIONS                              #
 ###############################################################################
@@ -345,7 +357,10 @@ def compare(im1, im2, exact, icc, cmyk):
             stderr=subprocess.PIPE,
         ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        assert psnr_re.fullmatch(psnr) is not None, psnr
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
 
@@ -501,7 +516,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False):
                 stderr=subprocess.PIPE,
             ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
     (tmpdir / "images-000.png").unlink()
@@ -5545,10 +5562,10 @@ def test_jpg_rot(tmp_path_factory, jpg_rot_img, jpg_rot_pdf):
 def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
     tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
     compare_ghostscript(
-        tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
+        tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8
     )
     # not testing with poppler as it cannot write CMYK images
-    compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=False, cmyk=True)
+    compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True)
     compare_pdfimages_cmyk(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf)
 
 
@@ -5902,10 +5919,16 @@ def test_tiff_float(tmp_path_factory, tiff_float_img, engine):
 def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
     tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
     compare_ghostscript(
-        tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
+        tmpdir,
+        tiff_cmyk8_img,
+        tiff_cmyk8_pdf,
+        gsdevice="tiff32nc",
+        exact=HAVE_EXACT_CMYK8,
     )
     # not testing with poppler as it cannot write CMYK images
-    compare_mupdf(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=False, cmyk=True)
+    compare_mupdf(
+        tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True
+    )
     compare_pdfimages_tiff(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf)
 
 
Oh wow, that imagemagick release is wild! I think that this commit might've fixed the in-exact cmyk issues: https://github.com/ImageMagick/ImageMagick/commit/c1ca2476540dd2f55ac108a190a75ff83a207a9c Can you try this new patch? ```patch diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 31b4043..72e67c4 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -75,6 +75,7 @@ for prog in ["convert", "compare", "identify"]: globals()[prog.upper()] = ["magick", prog] HAVE_IMAGEMAGICK_MODERN = True +HAVE_EXACT_CMYK8 = True try: ver = subprocess.check_output(CONVERT + ["-version"], stderr=subprocess.STDOUT) m = re.fullmatch( @@ -82,13 +83,18 @@ try: ) if m is None: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False else: if parse_version(m.group(1)) < parse_version("6.9.10-12"): HAVE_IMAGEMAGICK_MODERN = False + if parse_version(m.group(1)) < parse_version("7.1.0-48"): + HAVE_EXACT_CMYK8 = False except FileNotFoundError: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False except subprocess.CalledProcessError: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False if not HAVE_IMAGEMAGICK_MODERN: warnings.warn("imagemagick >= 6.9.10-12 not available, skipping certain checks...") @@ -113,6 +119,12 @@ except subprocess.CalledProcessError: if not HAVE_JP2: warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") +# the result of compare -metric PSNR is either just a floating point value or a +# floating point value following by the same value multiplied by 0.01, +# surrounded in parenthesis since ImagemMagick 7.1.0-48: +# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f +psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?))(?: \([0-9.]+\))?") + ############################################################################### # HELPER FUNCTIONS # ############################################################################### @@ -345,7 +357,10 @@ def compare(im1, im2, exact, icc, cmyk): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + assert psnr_re.fullmatch(psnr) is not None, psnr + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 @@ -501,7 +516,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 (tmpdir / "images-000.png").unlink() @@ -5545,10 +5562,10 @@ def test_jpg_rot(tmp_path_factory, jpg_rot_img, jpg_rot_pdf): def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") compare_ghostscript( - tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False + tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8 ) # not testing with poppler as it cannot write CMYK images - compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=False, cmyk=True) + compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True) compare_pdfimages_cmyk(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf) @@ -5902,10 +5919,16 @@ def test_tiff_float(tmp_path_factory, tiff_float_img, engine): def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") compare_ghostscript( - tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False + tmpdir, + tiff_cmyk8_img, + tiff_cmyk8_pdf, + gsdevice="tiff32nc", + exact=HAVE_EXACT_CMYK8, ) # not testing with poppler as it cannot write CMYK images - compare_mupdf(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=False, cmyk=True) + compare_mupdf( + tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True + ) compare_pdfimages_tiff(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf) ```
Author

Different errors now:

============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
rootdir: /build/img2pdf-0.4.4
collected 301 items / 12 deselected / 289 selected                             

src/img2pdf_test.py ....FFss................................ss.......... [ 17%]
....FF.................................................................. [ 42%]
........................................................................ [ 67%]
........................................................................ [ 92%]
.....................                                                    [100%]

=================================== FAILURES ===================================
___________________________ test_jpg_cmyk[internal] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
        compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8
        )
        # not testing with poppler as it cannot write CMYK images
>       compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True)

src/img2pdf_test.py:5351: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:412: in compare_mupdf
    compare(str(img), str(out), exact, False, cmyk)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/mupdf.pam', exact = True
icc = False, cmyk = True

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
>               raise Exception("cmyk cannot be exact")
E               Exception: cmyk cannot be exact

src/img2pdf_test.py:326: Exception
----------------------------- Captured stderr call -----------------------------
0page /build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf 1
____________________________ test_jpg_cmyk[pikepdf] ____________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg')
jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["darwin", "win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
        tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
        compare_ghostscript(
            tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8
        )
        # not testing with poppler as it cannot write CMYK images
>       compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True)

src/img2pdf_test.py:5351: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:412: in compare_mupdf
    compare(str(img), str(out), exact, False, cmyk)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg'
im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/mupdf.pam', exact = True
icc = False, cmyk = True

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
>               raise Exception("cmyk cannot be exact")
E               Exception: cmyk cannot be exact

src/img2pdf_test.py:326: Exception
----------------------------- Captured stderr call -----------------------------
0page /build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf 1
__________________________ test_tiff_cmyk8[internal] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
        compare_ghostscript(
            tmpdir,
            tiff_cmyk8_img,
            tiff_cmyk8_pdf,
            gsdevice="tiff32nc",
            exact=HAVE_EXACT_CMYK8,
        )
        # not testing with poppler as it cannot write CMYK images
>       compare_mupdf(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True
        )

src/img2pdf_test.py:5712: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:412: in compare_mupdf
    compare(str(img), str(out), exact, False, cmyk)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/mupdf.pam', exact = True
icc = False, cmyk = True

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
>               raise Exception("cmyk cannot be exact")
E               Exception: cmyk cannot be exact

src/img2pdf_test.py:326: Exception
----------------------------- Captured stderr call -----------------------------
0page /build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf 1
___________________________ test_tiff_cmyk8[pikepdf] ___________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0'))
tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff')
tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf')

    @pytest.mark.skipif(
        sys.platform in ["win32"],
        reason="test utilities not available on Windows and MacOS",
    )
    def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
        tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
        compare_ghostscript(
            tmpdir,
            tiff_cmyk8_img,
            tiff_cmyk8_pdf,
            gsdevice="tiff32nc",
            exact=HAVE_EXACT_CMYK8,
        )
        # not testing with poppler as it cannot write CMYK images
>       compare_mupdf(
            tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True
        )

src/img2pdf_test.py:5712: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/img2pdf_test.py:412: in compare_mupdf
    compare(str(img), str(out), exact, False, cmyk)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff'
im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/mupdf.pam', exact = True
icc = False, cmyk = True

    def compare(im1, im2, exact, icc, cmyk):
        if exact:
            if cmyk:
>               raise Exception("cmyk cannot be exact")
E               Exception: cmyk cannot be exact

src/img2pdf_test.py:326: Exception
----------------------------- Captured stderr call -----------------------------
0page /build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf 1
=============================== warnings summary ===============================
src/img2pdf_test.py:120
  /build/img2pdf-0.4.4/src/img2pdf_test.py:120: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks...
    warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - Exception: cmyk cannot ...
FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - Exception: cmyk cannot b...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - Exception: cmyk canno...
FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - Exception: cmyk cannot...
Different errors now: ```pytb ============================= test session starts ============================== platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0 rootdir: /build/img2pdf-0.4.4 collected 301 items / 12 deselected / 289 selected src/img2pdf_test.py ....FFss................................ss.......... [ 17%] ....FF.................................................................. [ 42%] ........................................................................ [ 67%] ........................................................................ [ 92%] ..................... [100%] =================================== FAILURES =================================== ___________________________ test_jpg_cmyk[internal] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8 ) # not testing with poppler as it cannot write CMYK images > compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True) src/img2pdf_test.py:5351: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:412: in compare_mupdf compare(str(img), str(out), exact, False, cmyk) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk1/mupdf.pam', exact = True icc = False, cmyk = True def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: > raise Exception("cmyk cannot be exact") E Exception: cmyk cannot be exact src/img2pdf_test.py:326: Exception ----------------------------- Captured stderr call ----------------------------- 0page /build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf0/out.pdf 1 ____________________________ test_jpg_cmyk[pikepdf] ____________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) jpg_cmyk_img = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg') jpg_cmyk_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["darwin", "win32"], reason="test utilities not available on Windows and MacOS", ) def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") compare_ghostscript( tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8 ) # not testing with poppler as it cannot write CMYK images > compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True) src/img2pdf_test.py:5351: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:412: in compare_mupdf compare(str(img), str(out), exact, False, cmyk) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk0/in.jpg' im2 = '/build/pytest-of-nixbld/pytest-0/jpg_cmyk2/mupdf.pam', exact = True icc = False, cmyk = True def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: > raise Exception("cmyk cannot be exact") E Exception: cmyk cannot be exact src/img2pdf_test.py:326: Exception ----------------------------- Captured stderr call ----------------------------- 0page /build/pytest-of-nixbld/pytest-0/jpg_cmyk_pdf1/out.pdf 1 __________________________ test_tiff_cmyk8[internal] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8, ) # not testing with poppler as it cannot write CMYK images > compare_mupdf( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True ) src/img2pdf_test.py:5712: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:412: in compare_mupdf compare(str(img), str(out), exact, False, cmyk) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk81/mupdf.pam', exact = True icc = False, cmyk = True def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: > raise Exception("cmyk cannot be exact") E Exception: cmyk cannot be exact src/img2pdf_test.py:326: Exception ----------------------------- Captured stderr call ----------------------------- 0page /build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf0/out.pdf 1 ___________________________ test_tiff_cmyk8[pikepdf] ___________________________ tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7ffff6a50970>, _basetemp=PosixPath('/build/pytest-of-nixbld/pytest-0')) tiff_cmyk8_img = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff') tiff_cmyk8_pdf = PosixPath('/build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf') @pytest.mark.skipif( sys.platform in ["win32"], reason="test utilities not available on Windows and MacOS", ) def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") compare_ghostscript( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8, ) # not testing with poppler as it cannot write CMYK images > compare_mupdf( tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True ) src/img2pdf_test.py:5712: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/img2pdf_test.py:412: in compare_mupdf compare(str(img), str(out), exact, False, cmyk) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ im1 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk80/in.tiff' im2 = '/build/pytest-of-nixbld/pytest-0/tiff_cmyk82/mupdf.pam', exact = True icc = False, cmyk = True def compare(im1, im2, exact, icc, cmyk): if exact: if cmyk: > raise Exception("cmyk cannot be exact") E Exception: cmyk cannot be exact src/img2pdf_test.py:326: Exception ----------------------------- Captured stderr call ----------------------------- 0page /build/pytest-of-nixbld/pytest-0/tiff_cmyk8_pdf1/out.pdf 1 =============================== warnings summary =============================== src/img2pdf_test.py:120 /build/img2pdf-0.4.4/src/img2pdf_test.py:120: UserWarning: imagemagick has no jpeg 2000 support, skipping certain checks... warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ FAILED src/img2pdf_test.py::test_jpg_cmyk[internal] - Exception: cmyk cannot ... FAILED src/img2pdf_test.py::test_jpg_cmyk[pikepdf] - Exception: cmyk cannot b... FAILED src/img2pdf_test.py::test_tiff_cmyk8[internal] - Exception: cmyk canno... FAILED src/img2pdf_test.py::test_tiff_cmyk8[pikepdf] - Exception: cmyk cannot... ```
Owner

Aha, of course! Here is another patch:

diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py
index 31b4043..a98d2de 100755
--- a/src/img2pdf_test.py
+++ b/src/img2pdf_test.py
@@ -75,6 +75,7 @@ for prog in ["convert", "compare", "identify"]:
         globals()[prog.upper()] = ["magick", prog]
 
 HAVE_IMAGEMAGICK_MODERN = True
+HAVE_EXACT_CMYK8 = True
 try:
     ver = subprocess.check_output(CONVERT + ["-version"], stderr=subprocess.STDOUT)
     m = re.fullmatch(
@@ -82,13 +83,18 @@ try:
     )
     if m is None:
         HAVE_IMAGEMAGICK_MODERN = False
+        HAVE_EXACT_CMYK8 = False
     else:
         if parse_version(m.group(1)) < parse_version("6.9.10-12"):
             HAVE_IMAGEMAGICK_MODERN = False
+        if parse_version(m.group(1)) < parse_version("7.1.0-48"):
+            HAVE_EXACT_CMYK8 = False
 except FileNotFoundError:
     HAVE_IMAGEMAGICK_MODERN = False
+    HAVE_EXACT_CMYK8 = False
 except subprocess.CalledProcessError:
     HAVE_IMAGEMAGICK_MODERN = False
+    HAVE_EXACT_CMYK8 = False
 
 if not HAVE_IMAGEMAGICK_MODERN:
     warnings.warn("imagemagick >= 6.9.10-12 not available, skipping certain checks...")
@@ -113,6 +119,12 @@ except subprocess.CalledProcessError:
 if not HAVE_JP2:
     warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...")
 
+# the result of compare -metric PSNR is either just a floating point value or a
+# floating point value following by the same value multiplied by 0.01,
+# surrounded in parenthesis since ImagemMagick 7.1.0-48:
+# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f
+psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?))(?: \([0-9.]+\))?")
+
 ###############################################################################
 #                               HELPER FUNCTIONS                              #
 ###############################################################################
@@ -310,8 +322,8 @@ def write_png(data, path, bitdepth, colortype, palette=None, iccp=None):
 
 def compare(im1, im2, exact, icc, cmyk):
     if exact:
-        if cmyk:
-            raise Exception("cmyk cannot be exact")
+        if cmyk and not HAVE_EXACT_CMYK8:
+            raise Exception("cmyk cannot be exact before ImageMagick 7.1.0-48")
         elif icc:
             raise Exception("icc cannot be exact")
         else:
@@ -345,7 +357,10 @@ def compare(im1, im2, exact, icc, cmyk):
             stderr=subprocess.PIPE,
         ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        assert psnr_re.fullmatch(psnr) is not None, psnr
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
 
@@ -501,7 +516,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False):
                 stderr=subprocess.PIPE,
             ).stderr
         assert psnr != b"0"
-        psnr = float(psnr.strip(b"0"))
+        assert psnr != b"0 (0)"
+        psnr = psnr_re.fullmatch(psnr).group(1)
+        psnr = float(psnr)
         assert psnr != 0  # or otherwise we would use the exact variant
         assert psnr > 50
     (tmpdir / "images-000.png").unlink()
@@ -5545,10 +5562,10 @@ def test_jpg_rot(tmp_path_factory, jpg_rot_img, jpg_rot_pdf):
 def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf):
     tmpdir = tmp_path_factory.mktemp("jpg_cmyk")
     compare_ghostscript(
-        tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False
+        tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8
     )
     # not testing with poppler as it cannot write CMYK images
-    compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=False, cmyk=True)
+    compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True)
     compare_pdfimages_cmyk(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf)
 
 
@@ -5902,10 +5919,16 @@ def test_tiff_float(tmp_path_factory, tiff_float_img, engine):
 def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf):
     tmpdir = tmp_path_factory.mktemp("tiff_cmyk8")
     compare_ghostscript(
-        tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False
+        tmpdir,
+        tiff_cmyk8_img,
+        tiff_cmyk8_pdf,
+        gsdevice="tiff32nc",
+        exact=HAVE_EXACT_CMYK8,
     )
     # not testing with poppler as it cannot write CMYK images
-    compare_mupdf(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=False, cmyk=True)
+    compare_mupdf(
+        tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True
+    )
     compare_pdfimages_tiff(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf)
 
 
Aha, of course! Here is another patch: ```patch diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 31b4043..a98d2de 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -75,6 +75,7 @@ for prog in ["convert", "compare", "identify"]: globals()[prog.upper()] = ["magick", prog] HAVE_IMAGEMAGICK_MODERN = True +HAVE_EXACT_CMYK8 = True try: ver = subprocess.check_output(CONVERT + ["-version"], stderr=subprocess.STDOUT) m = re.fullmatch( @@ -82,13 +83,18 @@ try: ) if m is None: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False else: if parse_version(m.group(1)) < parse_version("6.9.10-12"): HAVE_IMAGEMAGICK_MODERN = False + if parse_version(m.group(1)) < parse_version("7.1.0-48"): + HAVE_EXACT_CMYK8 = False except FileNotFoundError: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False except subprocess.CalledProcessError: HAVE_IMAGEMAGICK_MODERN = False + HAVE_EXACT_CMYK8 = False if not HAVE_IMAGEMAGICK_MODERN: warnings.warn("imagemagick >= 6.9.10-12 not available, skipping certain checks...") @@ -113,6 +119,12 @@ except subprocess.CalledProcessError: if not HAVE_JP2: warnings.warn("imagemagick has no jpeg 2000 support, skipping certain checks...") +# the result of compare -metric PSNR is either just a floating point value or a +# floating point value following by the same value multiplied by 0.01, +# surrounded in parenthesis since ImagemMagick 7.1.0-48: +# https://github.com/ImageMagick/ImageMagick/commit/751829cd4c911d7a42953a47c1f73068d9e7da2f +psnr_re = re.compile(rb"((?:inf|(?:0|[1-9][0-9]*)(?:\.[0-9]+)?))(?: \([0-9.]+\))?") + ############################################################################### # HELPER FUNCTIONS # ############################################################################### @@ -310,8 +322,8 @@ def write_png(data, path, bitdepth, colortype, palette=None, iccp=None): def compare(im1, im2, exact, icc, cmyk): if exact: - if cmyk: - raise Exception("cmyk cannot be exact") + if cmyk and not HAVE_EXACT_CMYK8: + raise Exception("cmyk cannot be exact before ImageMagick 7.1.0-48") elif icc: raise Exception("icc cannot be exact") else: @@ -345,7 +357,10 @@ def compare(im1, im2, exact, icc, cmyk): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + assert psnr_re.fullmatch(psnr) is not None, psnr + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 @@ -501,7 +516,9 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): stderr=subprocess.PIPE, ).stderr assert psnr != b"0" - psnr = float(psnr.strip(b"0")) + assert psnr != b"0 (0)" + psnr = psnr_re.fullmatch(psnr).group(1) + psnr = float(psnr) assert psnr != 0 # or otherwise we would use the exact variant assert psnr > 50 (tmpdir / "images-000.png").unlink() @@ -5545,10 +5562,10 @@ def test_jpg_rot(tmp_path_factory, jpg_rot_img, jpg_rot_pdf): def test_jpg_cmyk(tmp_path_factory, jpg_cmyk_img, jpg_cmyk_pdf): tmpdir = tmp_path_factory.mktemp("jpg_cmyk") compare_ghostscript( - tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=False + tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, gsdevice="tiff32nc", exact=HAVE_EXACT_CMYK8 ) # not testing with poppler as it cannot write CMYK images - compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=False, cmyk=True) + compare_mupdf(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True) compare_pdfimages_cmyk(tmpdir, jpg_cmyk_img, jpg_cmyk_pdf) @@ -5902,10 +5919,16 @@ def test_tiff_float(tmp_path_factory, tiff_float_img, engine): def test_tiff_cmyk8(tmp_path_factory, tiff_cmyk8_img, tiff_cmyk8_pdf): tmpdir = tmp_path_factory.mktemp("tiff_cmyk8") compare_ghostscript( - tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, gsdevice="tiff32nc", exact=False + tmpdir, + tiff_cmyk8_img, + tiff_cmyk8_pdf, + gsdevice="tiff32nc", + exact=HAVE_EXACT_CMYK8, ) # not testing with poppler as it cannot write CMYK images - compare_mupdf(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=False, cmyk=True) + compare_mupdf( + tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf, exact=HAVE_EXACT_CMYK8, cmyk=True + ) compare_pdfimages_tiff(tmpdir, tiff_cmyk8_img, tiff_cmyk8_pdf) ```
Author

Yes, all good now! Thanks!

Yes, all good now! Thanks!
josch referenced this issue from a commit 2022-09-15 02:37:07 +00:00
josch closed this issue 2022-09-15 02:37:08 +00:00
Owner

Thanks a lot for reporting this issue and helping with fixing it!

In Debian we do not have enough person-power to maintain imagemagick these days so we lack severely behind.

Does NixOS package every new imagemagick version and run tests for all packages depending on it?

I would appreciate more bug reports of this sort in the future! :)

Thanks a lot for reporting this issue and helping with fixing it! In Debian we do not have enough person-power to maintain imagemagick these days so we lack severely behind. Does NixOS package every new imagemagick version and run tests for all packages depending on it? I would appreciate more bug reports of this sort in the future! :)
Author

Yes, NixOS unstable is a rolling distro and we are usually pretty quick to update everything. We also run python tests when available, because the ecosystem is somewhat fragile for distros where there can be only one version of a python package. We can't test every reverse dependency of imagemagick immediately, but we'll notice these kinds of breakages quickly through appliations like paperless-ngx.

Thanks for the quick turn-around, we'll happily report more issues when we come across them.

Yes, NixOS unstable is a rolling distro and we are usually pretty quick to update everything. We also run python tests when available, because the ecosystem is somewhat fragile for distros where there can be only one version of a python package. We can't test every reverse dependency of imagemagick immediately, but we'll notice these kinds of breakages quickly through appliations like paperless-ngx. Thanks for the quick turn-around, we'll happily report more issues when we come across them.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#148
No description provided.