diff --git a/.travis.yml b/.travis.yml index 07e077e5..79b12bdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ script: - mv ocrmypdf dont_import_this_ocrmypdf - tesseract --version - qpdf --version -- pytest -s tests/test_main.py::test_qpdf_negative_zero +- pytest -n0 -s tests/test_qpdf.py - mv dont_import_this_ocrmypdf ocrmypdf deploy: diff --git a/tests/test_main.py b/tests/test_main.py index 28b87098..0a206e8e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python3 -# © 2015 James R. Barlow: github.com/jbarlow83 +# © 2015-17 James R. Barlow: github.com/jbarlow83 from subprocess import Popen, PIPE, check_output, check_call, DEVNULL import os @@ -1020,47 +1019,3 @@ def test_bad_locale(): assert p.returncode != 0 assert 'configured to use ASCII as encoding' in err, "should whine" - -@pytest.mark.timeout(30) -def test_qpdf_negative_zero(resources, outpdf): - negzero = resources / 'negzero.pdf' - hugemono = resources / 'hugemono.pdf' - # raises exception on err - qpdf.merge([str(negzero), str(hugemono)], outpdf, log=logging.getLogger()) - - -@pytest.mark.timeout(30) -@pytest.mark.parametrize('max_files,skip', [ - (2, 0), # Can we merge correctly without opening more than 2 files at once? - (16, 0), # And does this work properly when we can one-shot it? - (2, 1), # Or playing with even/odd - (3, 0) # Or odd step size - ]) -def test_qpdf_merge_correctness(resources, outpdf, max_files, skip): - # All of these must be only one page long - inputs = [ - '2400dpi.pdf', 'aspect.pdf', 'blank.pdf', 'ccitt.pdf', - 'linn.pdf', 'masks.pdf', 'poster.pdf', 'overlay.pdf', - 'skew.pdf', 'trivial.pdf', 'negzero.pdf'] - - input_files = [str(resources / f) for f in inputs] - - qpdf.merge( - input_files[skip:], outpdf, log=logging.getLogger(), - max_files=max_files) - assert len(PdfInfo(outpdf).pages) == len(input_files[skip:]) - - -@pytest.mark.timeout(30) -@pytest.mark.skipif( - True, - reason='qpdf binary cannot open multiple files multiple times') -def test_page_merge_ulimit(resources, outpdf): - # Ensure we can merge pages without opening one file descriptor per page - ulimits = resource.getrlimit(resource.RLIMIT_NOFILE) - page_count = ulimits[0] - print(page_count) - input_files = [str(resources / 'trivial.pdf')] * page_count - - qpdf.merge(input_files, outpdf, log=logging.getLogger()) - diff --git a/tests/test_qpdf.py b/tests/test_qpdf.py new file mode 100644 index 00000000..bf062509 --- /dev/null +++ b/tests/test_qpdf.py @@ -0,0 +1,55 @@ +# © 2017 James R. Barlow: github.com/jbarlow83 + +import logging +import resource +import pytest + +from ocrmypdf.exec import ghostscript, tesseract, qpdf +from ocrmypdf.pdfinfo import PdfInfo, Colorspace, Encoding + + +@pytest.mark.skipif( + qpdf.version() < '7.0.0', + reason="negzero.pdf crashes earlier versions") +def test_qpdf_negative_zero(resources, outpdf): + negzero = resources / 'negzero.pdf' + hugemono = resources / 'hugemono.pdf' + # raises exception on err + qpdf.merge([str(negzero), str(hugemono)], outpdf, log=logging.getLogger()) + + +@pytest.mark.timeout(15) +@pytest.mark.parametrize('max_files,skip', [ + (2, 0), # Can we merge correctly without opening more than 2 files at once? + (16, 0), # And does this work properly when we can one-shot it? + (2, 1), # Or playing with even/odd + (3, 0) # Or odd step size + ]) +def test_qpdf_merge_correctness(resources, outpdf, max_files, skip): + # All of these must be only one page long + inputs = [ + '2400dpi.pdf', 'aspect.pdf', 'blank.pdf', 'ccitt.pdf', + 'linn.pdf', 'masks.pdf', 'poster.pdf', 'overlay.pdf', + 'skew.pdf', 'trivial.pdf'] + + input_files = [str(resources / f) for f in inputs] + + qpdf.merge( + input_files[skip:], outpdf, log=logging.getLogger(), + max_files=max_files) + assert len(PdfInfo(outpdf).pages) == len(input_files[skip:]) + + +@pytest.mark.timeout(15) +@pytest.mark.skipif( + True, + reason='qpdf binary cannot open multiple files multiple times') +def test_page_merge_ulimit(resources, outpdf): + # Ensure we can merge pages without opening one file descriptor per page + ulimits = resource.getrlimit(resource.RLIMIT_NOFILE) + page_count = ulimits[0] + print(page_count) + input_files = [str(resources / 'trivial.pdf')] * page_count + + qpdf.merge(input_files, outpdf, log=logging.getLogger()) +