OCRmyPDF/tests/test_acroform.py

55 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-07-28 01:06:46 -07:00
# SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
2019-12-10 01:06:27 -08:00
2022-07-23 00:39:24 -07:00
from __future__ import annotations
import logging
2023-08-12 01:20:20 -07:00
import pikepdf
2019-12-10 01:06:27 -08:00
import pytest
import ocrmypdf
2021-04-07 01:56:51 -07:00
from .conftest import check_ocrmypdf
2019-12-10 01:06:27 -08:00
2021-04-07 02:09:45 -07:00
# pylint: disable=redefined-outer-name
2019-12-10 01:06:27 -08:00
@pytest.fixture
def acroform(resources):
return resources / 'acroform.pdf'
def test_acroform_and_redo(acroform, no_outpdf):
with pytest.raises(
ocrmypdf.exceptions.InputFileError, match='--redo-ocr is not currently possible'
):
2019-12-10 01:06:27 -08:00
check_ocrmypdf(acroform, no_outpdf, '--redo-ocr')
2020-06-01 03:06:40 -07:00
def test_acroform_message(acroform, caplog, outpdf):
caplog.set_level(logging.INFO)
2020-06-01 03:06:40 -07:00
check_ocrmypdf(acroform, outpdf, '--plugin', 'tests/plugins/tesseract_noop.py')
assert 'fillable form' in caplog.text
assert '--force-ocr' in caplog.text
2023-08-12 01:20:20 -07:00
@pytest.fixture
def digitally_signed(acroform, outdir):
out = outdir / 'acroform_signed.pdf'
with pikepdf.open(acroform) as pdf:
pdf.Root.AcroForm.SigFlags = 3
pdf.save(out)
yield out
def test_digital_signature(digitally_signed, no_outpdf):
with pytest.raises(ocrmypdf.exceptions.DigitalSignatureError):
check_ocrmypdf(digitally_signed, no_outpdf)
def test_digital_signature_invalidate(digitally_signed, no_outpdf):
check_ocrmypdf(
digitally_signed, no_outpdf, '--force-ocr', '--invalidate-digital-signatures'
)