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:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -17,6 +18,27 @@ from ocrmypdf.cli import get_options_and_plugins
|
|||||||
from ocrmypdf.exceptions import ExitCode
|
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():
|
def is_linux():
|
||||||
return platform.system() == 'Linux'
|
return platform.system() == 'Linux'
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ def test_gs_render_failure(resources, outpdf, caplog):
|
|||||||
exitcode = run_ocrmypdf_api(
|
exitcode = run_ocrmypdf_api(
|
||||||
resources / 'blank.pdf',
|
resources / 'blank.pdf',
|
||||||
outpdf,
|
outpdf,
|
||||||
|
'--output-type',
|
||||||
|
'pdfa', # Required to trigger Ghostscript PDF/A generation
|
||||||
'--plugin',
|
'--plugin',
|
||||||
'tests/plugins/tesseract_noop.py',
|
'tests/plugins/tesseract_noop.py',
|
||||||
'--plugin',
|
'--plugin',
|
||||||
@@ -110,6 +112,8 @@ def test_ghostscript_pdfa_failure(resources, outpdf, caplog):
|
|||||||
exitcode = run_ocrmypdf_api(
|
exitcode = run_ocrmypdf_api(
|
||||||
resources / 'francais.pdf',
|
resources / 'francais.pdf',
|
||||||
outpdf,
|
outpdf,
|
||||||
|
'--output-type',
|
||||||
|
'pdfa', # Required to trigger Ghostscript PDF/A generation
|
||||||
'--plugin',
|
'--plugin',
|
||||||
'tests/plugins/tesseract_noop.py',
|
'tests/plugins/tesseract_noop.py',
|
||||||
'--plugin',
|
'--plugin',
|
||||||
@@ -136,6 +140,8 @@ def test_ghostscript_mandatory_color_conversion(resources, outpdf):
|
|||||||
check_ocrmypdf(
|
check_ocrmypdf(
|
||||||
resources / 'jbig2_baddevicen.pdf',
|
resources / 'jbig2_baddevicen.pdf',
|
||||||
outpdf,
|
outpdf,
|
||||||
|
'--output-type',
|
||||||
|
'pdfa', # Required to trigger Ghostscript PDF/A generation
|
||||||
'--plugin',
|
'--plugin',
|
||||||
'tests/plugins/tesseract_noop.py',
|
'tests/plugins/tesseract_noop.py',
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user