Drop nose, all tests working reasonably again

Although the real issue was that the ruffus pipeline cannot be executed
twice in the same process due to its reliance on global variables.

The new OO pipeline in ruffus 2.6 would be one resolution that would
allow for more comprehensive testing as opposed to farming out the
execution to subprocess and inspecting the results, as is currently
done.
This commit is contained in:
James R. Barlow
2015-07-28 00:43:22 -07:00
parent 1c95597882
commit 8508141314
4 changed files with 27 additions and 31 deletions
+4 -1
View File
@@ -9,4 +9,7 @@ build/
dist/
*.egg-info/
venv/
*/test/output
*/test/output
bin/
include/
lib/
+5 -5
View File
@@ -8,7 +8,7 @@ from contextlib import suppress
import os
import sys
import shutil
from nose.tools import *
import pytest
from pkg_resources import Requirement, resource_filename
req = Requirement.parse('ocrmypdf')
@@ -75,11 +75,10 @@ def test_single_page_image():
assert pdfimage['bpc'] == 8
# DPI in a 1"x1" is the image width
eq_(pdfimage['dpi_w'], 8)
eq_(pdfimage['dpi_h'], 8)
assert pdfimage['dpi_w'] == 8
assert pdfimage['dpi_h'] == 8
@raises(NotImplementedError)
def test_single_page_inline_image():
filename = os.path.join(TEST_OUTPUT, 'image-mono-inline.pdf')
pdf = Canvas(filename, pagesize=(8*72, 6*72))
@@ -93,7 +92,8 @@ def test_single_page_inline_image():
pdf.showPage()
pdf.save()
pageinfo.pdf_get_all_pageinfo(filename)
with pytest.raises(NotImplementedError):
pageinfo.pdf_get_all_pageinfo(filename)
def test_jpeg():
+3 -1
View File
@@ -22,8 +22,10 @@ def _version():
try:
VERSION = _version()
AVAILABLE = True
except FileNotFoundError:
print("Could not find 'unpaper' executable", file=sys.stderr)
VERSION = '?'
AVAILABLE = False
raise
try:
+15 -24
View File
@@ -7,8 +7,7 @@ import shutil
from contextlib import suppress
import sys
from unittest.mock import patch, create_autospec
from nose import with_setup
from nose.tools import raises
import pytest
if sys.version_info.major < 3:
@@ -38,7 +37,7 @@ def run_ocrmypdf_sh(input_file, output_file, *args):
return sh, out, err
def check_ocrmypdf_sh(input_basename, output_basename, *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)
@@ -46,26 +45,16 @@ def check_ocrmypdf_sh(input_basename, output_basename, *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 or empty"
def run_ocrmypdf(input_basename, output_basename, *args):
input_file = os.path.join(TEST_RESOURCES, input_basename)
output_file = os.path.join(TEST_OUTPUT, output_basename)
sys_argv = list(args) + [input_file, output_file]
with patch.object(sys, 'argv', sys_argv):
import ocrmypdf.main
ocrmypdf.main.run_pipeline()
return output_file
def xtest_quick():
check_ocrmypdf_sh('c02-22.pdf', 'test_quick.pdf')
def test_quick():
check_ocrmypdf('c02-22.pdf', 'test_quick.pdf')
def xtest_deskew():
def test_deskew():
# Run with deskew
deskewed_pdf = run_ocrmypdf('skew.pdf', 'test_deskew.pdf', '-d')
deskewed_pdf = check_ocrmypdf('skew.pdf', 'test_deskew.pdf', '-d')
# Now render as an image again and use Leptonica to find the skew angle
# to confirm that it was deskewed
@@ -92,12 +81,12 @@ def xtest_deskew():
assert -0.5 < skew_angle < 0.5, "Deskewing failed"
def xtest_clean():
check_ocrmypdf_sh('skew.pdf', 'test_clean.pdf', '-c')
def test_clean():
check_ocrmypdf('skew.pdf', 'test_clean.pdf', '-c')
def test_metadata():
pdf = run_ocrmypdf(
pdf = check_ocrmypdf(
'c02-22.pdf', 'test_metadata.pdf',
'--title', 'Du siehst den Wald vor lauter Bäumen nicht.',
'--author', '孔子',
@@ -117,7 +106,7 @@ def test_metadata():
def check_oversample(renderer):
oversampled_pdf = run_ocrmypdf(
oversampled_pdf = check_ocrmypdf(
'skew.pdf', 'test_oversample_%s.pdf' % renderer, '--oversample', '300',
'--pdf-renderer', renderer)
@@ -134,12 +123,14 @@ def test_oversample():
yield check_oversample, 'tesseract'
@raises(SystemExit)
def test_repeat_ocr():
run_ocrmypdf('graph_ocred.pdf', 'wontwork.pdf')
sh, _, _ = run_ocrmypdf_sh('graph_ocred.pdf', 'wontwork.pdf')
assert sh.returncode != 0
def test_force_ocr():
run_ocrmypdf('graph_ocred.pdf', 'test_force.pdf')
check_ocrmypdf('graph_ocred.pdf', 'test_force.pdf', '-f')
def test_skip_ocr():
check_ocrmypdf('graph_ocred.pdf', 'test_skip.pdf', '-s')