From 4812b20fb2f452373b848f214d3728e1e9e36756 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 10 Jan 2018 16:35:31 -0800 Subject: [PATCH] Fix tesseract_noop.py generating wrong size of output PDF in tests This caused trouble before with test_deskew --- tests/spoof/tesseract_noop.py | 5 +++-- tests/test_main.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/spoof/tesseract_noop.py b/tests/spoof/tesseract_noop.py index 8ec9062a..fcd83d8e 100755 --- a/tests/spoof/tesseract_noop.py +++ b/tests/spoof/tesseract_noop.py @@ -73,10 +73,11 @@ def main(): output = sys.argv[-3] with Image.open(inputf) as im: dpi = im.info['dpi'] - imsize = im.size[0] * dpi[0] / 72, im.size[1] * dpi[1] / 72 + pagesize = im.size[0] / dpi[0], im.size[1] / dpi[1] + ptsize = pagesize[0] * 72, pagesize[1] * 72 pdf_out = pypdf.PdfFileWriter() - pdf_out.addBlankPage(imsize[0], imsize[1]) + pdf_out.addBlankPage(ptsize[0], ptsize[1]) with open(output + '.pdf', 'wb') as f: pdf_out.write(f) with open(output + '.txt', 'w') as f: diff --git a/tests/test_main.py b/tests/test_main.py index ca5c02b6..20e1e0a3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -71,11 +71,10 @@ def test_quick(spoof_tesseract_cache, resources, outpdf): check_ocrmypdf(resources / 'ccitt.pdf', outpdf, env=spoof_tesseract_cache) -@pytest.mark.filterwarnings('ignore:Image size') def test_deskew(spoof_tesseract_noop, resources, outdir): # Run with deskew deskewed_pdf = check_ocrmypdf( - resources / 'skew.pdf', outdir / 'skew.pdf', '-d', '-v', '1', + resources / 'skew.pdf', outdir / 'skew.pdf', '-d', env=spoof_tesseract_noop) # Now render as an image again and use Leptonica to find the skew angle @@ -90,7 +89,8 @@ def test_deskew(spoof_tesseract_noop, resources, outdir): xres=150, yres=150, raster_device='pngmono', - log=log) + log=log, + pageno=1) from ocrmypdf.leptonica import Pix pix = Pix.read(str(deskewed_png)) @@ -129,8 +129,8 @@ def test_remove_background(spoof_tesseract_noop, resources, outdir): xres=100, yres=100, raster_device='png16m', - log=log) - + log=log, + pageno=1) # The output image should contain pure white and black im = Image.open(output_png)