tests: fix test_page_boxes when verapdf unavailable
The test expected MediaBox preservation for pdfa output, but this only works when verapdf is available for speculative PDF/A conversion. Without verapdf (Linux/Windows CI), Ghostscript normalizes the MediaBox. Also convert pikepdf.Array to list in assertions for clearer error messages, avoiding pytest repr issues with pikepdf objects.
This commit is contained in:
@@ -6,6 +6,8 @@ from __future__ import annotations
|
||||
import pikepdf
|
||||
import pytest
|
||||
|
||||
from ocrmypdf._exec import verapdf
|
||||
|
||||
from .conftest import check_ocrmypdf
|
||||
|
||||
page_rect = [0, 0, 612, 792]
|
||||
@@ -14,12 +16,14 @@ wh_rect = [0, 0, 412, 592]
|
||||
|
||||
neg_rect = [-100, -100, 512, 692]
|
||||
|
||||
# When speculative PDF/A succeeds (verapdf available), MediaBox is preserved.
|
||||
# Ghostscript would normalize MediaBox to start at origin, but speculative
|
||||
# conversion bypasses Ghostscript.
|
||||
_pdfa_inset_expected = inset_rect if verapdf.available() else wh_rect
|
||||
|
||||
mediabox_testdata = [
|
||||
# When speculative PDF/A succeeds (verapdf available), MediaBox is preserved.
|
||||
# Ghostscript would normalize MediaBox to start at origin, but speculative
|
||||
# conversion bypasses Ghostscript.
|
||||
('fpdf2', 'pdfa', 'ccitt.pdf', None, inset_rect, inset_rect),
|
||||
('sandwich', 'pdfa', 'ccitt.pdf', None, inset_rect, inset_rect),
|
||||
('fpdf2', 'pdfa', 'ccitt.pdf', None, inset_rect, _pdfa_inset_expected),
|
||||
('sandwich', 'pdfa', 'ccitt.pdf', None, inset_rect, _pdfa_inset_expected),
|
||||
('fpdf2', 'pdf', 'ccitt.pdf', None, inset_rect, inset_rect),
|
||||
('sandwich', 'pdf', 'ccitt.pdf', None, inset_rect, inset_rect),
|
||||
(
|
||||
@@ -68,7 +72,7 @@ def test_media_box(
|
||||
|
||||
with pikepdf.open(outdir / 'processed.pdf') as pdf:
|
||||
page = pdf.pages[0]
|
||||
assert page.mediabox == crop_expected
|
||||
assert [float(x) for x in page.mediabox] == crop_expected
|
||||
|
||||
|
||||
cropbox_testdata = [
|
||||
@@ -122,4 +126,4 @@ def test_crop_box(
|
||||
|
||||
with pikepdf.open(outdir / 'processed.pdf') as pdf:
|
||||
page = pdf.pages[0]
|
||||
assert page.cropbox == crop_expected
|
||||
assert [float(x) for x in page.cropbox] == crop_expected
|
||||
|
||||
Reference in New Issue
Block a user