Skip to content

Tests fail with Pillow 8.3.1 #802

@QuLogic

Description

@QuLogic

Describe the bug
I believe this upgrade from Pillow 8.2.0 to 8.3.1 caused two new failures:

____________________________ test_rasterize_rotated ____________________________
[gw3] linux -- Python 3.10.0 /usr/bin/python3
francais = (PosixPath('/builddir/build/BUILD/ocrmypdf-12.2.0/tests/resources/francais.pdf'), <pikepdf.Pdf description='/builddir/build/BUILD/ocrmypdf-12.2.0/tests/resources/francais.pdf'>)
outdir = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_rasterize_rotated0')
caplog = <_pytest.logging.LogCaptureFixture object at 0x7fff7b598130>
    def test_rasterize_rotated(francais, outdir, caplog):
        path, pdf = francais
        page_size_pts = (pdf.pages[0].MediaBox[2], pdf.pages[0].MediaBox[3])
        assert pdf.pages[0].MediaBox[0] == pdf.pages[0].MediaBox[1] == 0
        page_size = (page_size_pts[0] / Decimal(72), page_size_pts[1] / Decimal(72))
        target_size = Decimal('50.0'), Decimal('30.0')
        forced_dpi = Resolution(42.0, 4242.0)
    
        caplog.set_level(logging.DEBUG)
        rasterize_pdf(
            path,
            outdir / 'out.png',
            raster_device='pngmono',
            raster_dpi=Resolution(
                target_size[0] / page_size[0], target_size[1] / page_size[1]
            ),
            page_dpi=forced_dpi,
            rotation=90,
        )
    
        with Image.open(outdir / 'out.png') as im:
            assert im.size == (target_size[1], target_size[0])
>           assert im.info['dpi'] == (forced_dpi[1], forced_dpi[0])
E           assert (4242.0032, 42.0116) == (4242.0, 42.0)
E             At index 0 diff: 4242.0032 != 4242.0
E             Use -v to get the full diff
tests/test_ghostscript.py:75: AssertionError
------------------------------ Captured log call -------------------------------
DEBUG    ocrmypdf.subprocess:__init__.py:112 Running: ['gs', '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-sDEVICE=pngmono', '-dFirstPage=1', '-dLastPage=1', '-r16.666667x10.000000', '-o', '-', '-sstdout=%stderr', '-dAutoRotatePages=/None', '-f', '/builddir/build/BUILD/ocrmypdf-12.2.0/tests/resources/francais.pdf']
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'IHDR' 16 13
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'iCCP' 41 2296
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:391 iCCP profile name b'default_gray.icc'
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:392 Compression method 0
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'pHYs' 2349 9
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'tEXt' 2370 31
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'IDAT' 2413 63
DEBUG    ocrmypdf._exec.ghostscript:ghostscript.py:126 Rotating output by 90
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'IHDR' 16 13
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'iCCP' 41 2291
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:391 iCCP profile name b'ICC Profile'
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:392 Compression method 0
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'pHYs' 2344 9
DEBUG    PIL.PngImagePlugin:PngImagePlugin.py:186 STREAM b'IDAT' 2365 106
_____________________________ test_rasterize_size ______________________________
[gw0] linux -- Python 3.10.0 /usr/bin/python3
francais = (PosixPath('/builddir/build/BUILD/ocrmypdf-12.2.0/tests/resources/francais.pdf'), <pikepdf.Pdf description='/builddir/build/BUILD/ocrmypdf-12.2.0/tests/resources/francais.pdf'>)
outdir = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_rasterize_size0')
    def test_rasterize_size(francais, outdir):
        path, pdf = francais
        page_size_pts = (pdf.pages[0].MediaBox[2], pdf.pages[0].MediaBox[3])
        assert pdf.pages[0].MediaBox[0] == pdf.pages[0].MediaBox[1] == 0
        page_size = (page_size_pts[0] / Decimal(72), page_size_pts[1] / Decimal(72))
        target_size = Decimal('50.0'), Decimal('30.0')
        forced_dpi = Resolution(42.0, 4242.0)
    
        rasterize_pdf(
            path,
            outdir / 'out.png',
            raster_device='pngmono',
            raster_dpi=Resolution(
                target_size[0] / page_size[0], target_size[1] / page_size[1]
            ),
            page_dpi=forced_dpi,
        )
    
        with Image.open(outdir / 'out.png') as im:
            assert im.size == target_size
>           assert im.info['dpi'] == forced_dpi
E           assert (42.0116, 4242.0032) == Resolution(42.0x4242.0 dpi)
E             At index 0 diff: 42.0116 != 42.0
E             Use -v to get the full diff
tests/test_ghostscript.py:50: AssertionError

To Reproduce
/usr/bin/pytest -ra -n auto --runslow

Expected behavior
Tests pass

System (please complete the following information):

  • OS: Fedora Rawhide (35)
  • Python version: 3.10.0b3
  • OCRmyPDF version: 12.2.0

Installation
Building from source

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions