New test: check skew

This commit is contained in:
Jim Barlow
2015-07-22 04:00:59 -07:00
parent ce2dbdf372
commit 6d5d8be708
2 changed files with 23 additions and 11 deletions
Binary file not shown.
+23 -11
View File
@@ -2,6 +2,8 @@
from subprocess import Popen, PIPE
import os
import shutil
from contextlib import suppress
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
@@ -11,17 +13,14 @@ TEST_OUTPUT = os.path.join(PROJECT_ROOT, 'tests', 'output')
def setup_module():
try:
with suppress(FileNotFoundError):
shutil.rmtree(TEST_OUTPUT)
with suppress(FileExistsError):
os.mkdir(TEST_OUTPUT)
except FileExistsError:
pass
def run_ocrmypdf(input_file, *args):
input_path = os.path.join(TEST_RESOURCES, input_file)
output_path = os.path.join(TEST_OUTPUT, input_file)
sh_args = ['sh', './OCRmyPDF.sh'] + list(args) + [input_path, output_path]
def run_ocrmypdf(input_file, output_file, *args):
sh_args = ['sh', OCRMYPDF] + list(args) + [input_file, output_file]
sh = Popen(
sh_args, close_fds=True, stdout=PIPE, stderr=PIPE,
universal_newlines=True)
@@ -29,10 +28,23 @@ def run_ocrmypdf(input_file, *args):
return sh, out, err
def check_ocrmypdf(input_file, *args):
sh, _, err = run_ocrmypdf(input_file, *args)
def check_ocrmypdf(input_basename, output_basename, *args):
input_file = os.path.join(TEST_RESOURCES, input_basename)
output_file = os.path.join(TEST_OUTPUT, output_basename or input_basename)
sh, _, err = run_ocrmypdf(input_file, output_file, *args)
assert sh.returncode == 0, err
assert os.path.exists(output_file), "Output file not created"
assert os.stat(output_file).st_size > 100, "PDF too small, empty or near empty"
def test_quick():
check_ocrmypdf('c02-22.pdf')
check_ocrmypdf('c02-22.pdf', 'test_quick.pdf')
def test_deskew():
check_ocrmypdf('skew.pdf', 'test_deskew.pdf', '-d')
def test_clean():
check_ocrmypdf('skew.pdf', 'test_clean.pdf', '-c')