From 164cf2dc8aa22cb5a72e5fdf1c978969a61aaae7 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Jun 2026 12:48:33 -0700 Subject: [PATCH] test: use bundled font in gray-mask test for macOS/Windows portability test_gray_mask_ocrs_to_text loaded DejaVu, which only exists on the Linux CI runners; the OSError fallback hardcoded a Linux-only path, so the test failed with "cannot open resource" on macOS and Windows. Load the bundled ocrmypdf.data/NotoSans-Regular.ttf via importlib.resources instead, which is guaranteed present on every platform. --- tests/test_rasterizer.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_rasterizer.py b/tests/test_rasterizer.py index 6011fbee..0b426790 100644 --- a/tests/test_rasterizer.py +++ b/tests/test_rasterizer.py @@ -250,18 +250,18 @@ def _make_text_mask_pdf(path, fill: bytes): this reproduces issue #1688: the text is mid-gray, which is dithered into noise if rasterized to 1-bit but reads correctly once promoted to gray. """ + from importlib.resources import as_file, files + from PIL import ImageDraw, ImageFont w, h = 1700, 600 im = Image.new('1', (w, h), 1) # 1 = white = "do not paint" under Decode [0 1] draw = ImageDraw.Draw(im) - try: - font = ImageFont.truetype("DejaVuSans-Bold.ttf", 220) - except OSError: - font = ImageFont.truetype( - "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 220 - ) - draw.text((40, 120), "TESTING", fill=0, font=font) + # Use a font bundled with ocrmypdf so this test is portable across platforms; + # system fonts like DejaVu are not present on macOS/Windows CI runners. + with as_file(files('ocrmypdf.data') / 'NotoSans-Regular.ttf') as font_path: + font = ImageFont.truetype(str(font_path), 220) + draw.text((40, 120), "TESTING", fill=0, font=font) packed = im.tobytes() # 1-bpc, rows byte-padded, MSB first pdf = pikepdf.Pdf.new()