diff --git a/ocrmypdf/__main__.py b/ocrmypdf/__main__.py index 3ea968c1..55cb8e91 100755 --- a/ocrmypdf/__main__.py +++ b/ocrmypdf/__main__.py @@ -333,6 +333,10 @@ def check_options_advanced(options, log): if options.tesseract_oem and not tesseract.v4(): log.warning( "--tesseract-oem requires Tesseract 4.x -- argument ignored") + if options.pdf_renderer == 'tess4' and not tesseract.has_textonly_pdf(): + raise MissingDependencyError( + "--pdf-renderer tess4 requires Tesseract 4.x " + "commit 3d9fb3b or later") def check_options(options, log): diff --git a/tests/test_tess3.py b/tests/test_tess3.py new file mode 100644 index 00000000..0861ebcf --- /dev/null +++ b/tests/test_tess3.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +# © 2017 James R. Barlow: github.com/jbarlow83 + +import pytest +from ocrmypdf.exceptions import ExitCode +from ocrmypdf.exec import tesseract + + +# Skip all tests in this file if not tesseract 3 +pytestmark = pytest.mark.skipif(tesseract.v4(), + reason="tesseract 3.x required") + + +def test_textonly_pdf_on_tess3(resources, no_outpdf): + p, _, _ = pytest.helpers.run_ocrmypdf( + resources / 'linn.pdf', + no_outpdf, '--pdf-renderer', 'tess4') + + assert p.returncode == ExitCode.missing_dependency + + +def test_oem_on_tess3(resources, no_outpdf): + p, _, err = pytest.helpers.run_ocrmypdf( + resources / 'aspect.pdf', + no_outpdf, '--tesseract-oem', '1') + + assert p.returncode == ExitCode.ok + assert 'argument ignored' in err diff --git a/tests/test_tess4.py b/tests/test_tess4.py index efbbc8e6..5f3b3848 100644 --- a/tests/test_tess4.py +++ b/tests/test_tess4.py @@ -1,17 +1,8 @@ #!/usr/bin/env python3 # © 2017 James R. Barlow: github.com/jbarlow83 -from subprocess import Popen, PIPE, check_output, check_call, DEVNULL -import os -import shutil -from contextlib import suppress -import sys import pytest -from ocrmypdf.pageinfo import pdf_get_all_pageinfo -import PyPDF2 as pypdf from ocrmypdf.exceptions import ExitCode -from ocrmypdf import leptonica -from ocrmypdf.pdfa import file_claims_pdfa from ocrmypdf.exec import tesseract