Fix Ghostscript tests after default output type changed to 'auto'

- Add --output-type pdfa to tests that exercise Ghostscript-specific
  behavior (test_gs_render_failure, test_ghostscript_pdfa_failure,
  test_ghostscript_mandatory_color_conversion)
- Add Gs106WarningFilter to suppress expected Ghostscript 10.6.x JPEG
  encoding warning in test logs
This commit is contained in:
James R. Barlow
2026-01-09 01:02:25 -08:00
parent 0c4ee5af4e
commit 122450c19e
2 changed files with 28 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
import platform
import sys
from pathlib import Path
@@ -17,6 +18,27 @@ from ocrmypdf.cli import get_options_and_plugins
from ocrmypdf.exceptions import ExitCode
class Gs106WarningFilter(logging.Filter):
"""Filter out expected Ghostscript 10.6.x warning from test logs."""
def filter(self, record: logging.LogRecord) -> bool:
# Allow all records except the expected Ghostscript 10.6.x warning
if "Ghostscript 10.6.x contains JPEG encoding errors" in record.getMessage():
return False
return True
@pytest.fixture(autouse=True)
def suppress_gs106_warning():
"""Suppress the expected Ghostscript 10.6.x JPEG encoding warning in tests."""
# Add filter to root logger to suppress expected warnings
root_logger = logging.getLogger()
warning_filter = Gs106WarningFilter()
root_logger.addFilter(warning_filter)
yield
root_logger.removeFilter(warning_filter)
def is_linux():
return platform.system() == 'Linux'

View File

@@ -84,6 +84,8 @@ def test_gs_render_failure(resources, outpdf, caplog):
exitcode = run_ocrmypdf_api(
resources / 'blank.pdf',
outpdf,
'--output-type',
'pdfa', # Required to trigger Ghostscript PDF/A generation
'--plugin',
'tests/plugins/tesseract_noop.py',
'--plugin',
@@ -110,6 +112,8 @@ def test_ghostscript_pdfa_failure(resources, outpdf, caplog):
exitcode = run_ocrmypdf_api(
resources / 'francais.pdf',
outpdf,
'--output-type',
'pdfa', # Required to trigger Ghostscript PDF/A generation
'--plugin',
'tests/plugins/tesseract_noop.py',
'--plugin',
@@ -136,6 +140,8 @@ def test_ghostscript_mandatory_color_conversion(resources, outpdf):
check_ocrmypdf(
resources / 'jbig2_baddevicen.pdf',
outpdf,
'--output-type',
'pdfa', # Required to trigger Ghostscript PDF/A generation
'--plugin',
'tests/plugins/tesseract_noop.py',
)