Take a stab at writing test case for autorotate

This commit is contained in:
James R. Barlow
2016-02-08 12:32:39 -08:00
parent d30a879e2d
commit 7c0940609a
3 changed files with 27 additions and 2 deletions
+4 -1
View File
@@ -7,7 +7,8 @@ from shutil import copy
from . import get_program
def rasterize_pdf(input_file, output_file, xres, yres, raster_device, log):
def rasterize_pdf(input_file, output_file, xres, yres, raster_device, log,
pageno=1):
with NamedTemporaryFile(delete=True) as tmp:
args_gs = [
get_program('gs'),
@@ -15,6 +16,8 @@ def rasterize_pdf(input_file, output_file, xres, yres, raster_device, log):
'-dBATCH',
'-dNOPAUSE',
'-sDEVICE=%s' % raster_device,
'-dFirstPage=%i' % pageno,
'-dLastPage=%i' % pageno,
'-o', tmp.name,
'-r{0}x{1}'.format(str(xres), str(yres)),
input_file
+1 -1
View File
@@ -1 +1 @@
pytest>=2.7.2
pytest>=2.7.2
+22
View File
@@ -238,6 +238,28 @@ def test_argsfile(spoof_tesseract_noop):
env=spoof_tesseract_noop)
@pytest.mark.parametrize('renderer', [
'hocr',
'tesseract',
])
def test_autorotate(spoof_tesseract_cache, renderer):
import ocrmypdf.ghostscript as ghostscript
import logging
gslog = logging.getLogger()
out = check_ocrmypdf('cardinal.pdf', 'test_autorotate_%s.pdf' % renderer,
'-r', '-v', '1')
for n in range(1, 4+1):
ghostscript.rasterize_pdf(
out, _make_output('cardinal-%i.png' % n), xres=100, yres=100,
raster_device='pngmono', log=gslog, pageno=n)
ghostscript.rasterize_pdf(
_make_input('cardinal.pdf'), _make_output('reference.png'),
xres=100, yres=100, raster_device='pngmono', log=gslog, pageno=1)
@pytest.mark.parametrize('renderer', [
'hocr',
'tesseract',