2017-01-26 12:28:51 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# © 2017 James R. Barlow: github.com/jbarlow83
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from ocrmypdf.exceptions import ExitCode
|
|
|
|
from ocrmypdf.exec import tesseract
|
2017-03-24 13:23:03 -07:00
|
|
|
from ocrmypdf import pageinfo
|
|
|
|
import sys
|
2017-01-26 12:28:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
# Skip all tests in this file if not tesseract 4
|
2017-03-24 13:23:03 -07:00
|
|
|
pytestmark = pytest.mark.skipif(
|
|
|
|
not (tesseract.v4() and tesseract.has_textonly_pdf()),
|
|
|
|
reason="tesseract 4.0 with textonly_pdf feature required")
|
|
|
|
|
|
|
|
check_ocrmypdf = pytest.helpers.check_ocrmypdf
|
|
|
|
run_ocrmypdf = pytest.helpers.run_ocrmypdf
|
|
|
|
spoof = pytest.helpers.spoof
|
2017-01-26 12:28:51 -08:00
|
|
|
|
|
|
|
|
2017-01-26 16:38:59 -08:00
|
|
|
def test_textonly_pdf(resources, outdir):
|
2017-03-24 13:23:03 -07:00
|
|
|
check_ocrmypdf(
|
2017-01-26 16:38:59 -08:00
|
|
|
resources / 'linn.pdf',
|
|
|
|
outdir / 'linn_textonly.pdf', '--pdf-renderer', 'tess4')
|
2017-01-26 12:28:51 -08:00
|
|
|
|
|
|
|
|
2017-03-24 13:23:03 -07:00
|
|
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs math.isclose")
|
|
|
|
def test_pagesize_consistency_tess4(resources, outpdf):
|
|
|
|
from math import isclose
|
|
|
|
|
|
|
|
infile = resources / 'linn.pdf'
|
|
|
|
|
|
|
|
before_dims = pytest.helpers.first_page_dimensions(infile)
|
|
|
|
|
|
|
|
check_ocrmypdf(
|
|
|
|
infile,
|
|
|
|
outpdf, '--pdf-renderer', 'tess4',
|
|
|
|
'--clean', '--deskew', '--remove-background', '--clean-final')
|
|
|
|
|
|
|
|
after_dims = pytest.helpers.first_page_dimensions(outpdf)
|
2017-01-26 12:28:51 -08:00
|
|
|
|
2017-03-24 13:23:03 -07:00
|
|
|
assert isclose(before_dims[0], after_dims[0])
|
|
|
|
assert isclose(before_dims[1], after_dims[1])
|