diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 42163ae7..4c1c8646 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -32,6 +32,7 @@ v12.0.0 - Some deprecated functions in ``ocrmypdf.optimize`` were removed. - The ``ocrmypdf.leptonica`` module is now deprecated. - Continuous integration moved to GitHub Actions. +- We no longer depend on ``pytest_helpers_namespace`` for testing. **New features** diff --git a/requirements/test.txt b/requirements/test.txt index fea870d7..72225e2d 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,4 @@ pytest >= 6.0.0 -pytest-helpers-namespace >= 2019.1.8 pytest-xdist >= 2.2.0 pytest-cov >= 2.11.1 python-xmp-toolkit == 2.0.1 # requires apt-get install libexempi3 diff --git a/src/ocrmypdf/RELEASE.md b/src/ocrmypdf/RELEASE.md new file mode 100644 index 00000000..41a40e97 --- /dev/null +++ b/src/ocrmypdf/RELEASE.md @@ -0,0 +1,35 @@ +# Release checklist + +## Patch release + +- Check `pytest` + +- Update release notes + +## Minor release + +## Major release + +- Run `pre-commit autoupdate` + +- Check README.md + +- Check setup.py + + - Are classifiers up to date? + - Is `python_requires` correct? + - Python 3.6 is EOL on December 2021-12. Could drop support then. + - Can we tighten any `install_requires` dependencies? + +- Search for old version shims we can remove + + - "shim" + - ` pikepdf.__version__` + +- Search for deprecation: search all files for deprec*, etc. + +- Check requirements/* + +- Delete `tests/cache`, do `pytest --runslow`, and update cache. + +- Do `pytest --cov-report html` diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..f714d74d --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,7 @@ +# © 2021 James R. Barlow: github.com/jbarlow83 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Empty __init__.py file diff --git a/tests/conftest.py b/tests/conftest.py index 70741548..d3b3ebb7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,37 +20,29 @@ from ocrmypdf._plugin_manager import get_parser_options_plugins pytest_plugins = ['helpers_namespace'] -# pylint: disable=E1101 -# pytest.helpers is dynamic so it confuses pylint - if sys.version_info < (3, 5): print("Requires Python 3.5+") sys.exit(1) -@pytest.helpers.register def is_linux(): return platform.system() == 'Linux' -@pytest.helpers.register def is_macos(): return platform.system() == 'Darwin' -@pytest.helpers.register def running_in_docker(): # Docker creates a file named /.dockerenv (newer versions) or # /.dockerinit (older) -- this is undocumented, not an offical test return Path('/.dockerenv').exists() or Path('/.dockerinit').exists() -@pytest.helpers.register def running_in_travis(): return os.environ.get('TRAVIS') == 'true' -@pytest.helpers.register def have_unpaper(): try: unpaper.version() @@ -93,7 +85,6 @@ def no_outpdf(tmp_path): return tmp_path / 'no_output.pdf' -@pytest.helpers.register def check_ocrmypdf(input_file, output_file, *args): """Run ocrmypdf and confirmed that a valid file was created""" args = [str(input_file), str(output_file)] + [ @@ -111,7 +102,6 @@ def check_ocrmypdf(input_file, output_file, *args): return output_file -@pytest.helpers.register def run_ocrmypdf_api(input_file, output_file, *args): """Run ocrmypdf via API and let caller deal with results @@ -127,7 +117,6 @@ def run_ocrmypdf_api(input_file, output_file, *args): return api.run_pipeline(options, plugin_manager=None, api=False) -@pytest.helpers.register def run_ocrmypdf(input_file, output_file, *args, text=True): "Run ocrmypdf and let caller deal with results" @@ -150,7 +139,6 @@ def run_ocrmypdf(input_file, output_file, *args, text=True): return p, p.stdout, p.stderr -@pytest.helpers.register def first_page_dimensions(pdf): info = pdfinfo.PdfInfo(pdf) page0 = info[0] diff --git a/tests/test_acroform.py b/tests/test_acroform.py index f6932ebe..910bacc8 100644 --- a/tests/test_acroform.py +++ b/tests/test_acroform.py @@ -11,7 +11,7 @@ import pytest import ocrmypdf -check_ocrmypdf = pytest.helpers.check_ocrmypdf +from .conftest import check_ocrmypdf @pytest.fixture diff --git a/tests/test_completion.py b/tests/test_completion.py index 4ac753b8..20d716ff 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -10,8 +10,10 @@ from subprocess import PIPE, run import pytest +from .conftest import running_in_docker + pytestmark = pytest.mark.skipif( - pytest.helpers.running_in_docker(), # pylint: disable=no-member + running_in_docker(), reason="docker can't complete", ) diff --git a/tests/test_ghostscript.py b/tests/test_ghostscript.py index 37a1a1e9..4995fb94 100644 --- a/tests/test_ghostscript.py +++ b/tests/test_ghostscript.py @@ -16,9 +16,7 @@ from ocrmypdf._exec.ghostscript import rasterize_pdf from ocrmypdf.exceptions import ExitCode from ocrmypdf.helpers import Resolution -check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=no-member -run_ocrmypdf = pytest.helpers.run_ocrmypdf # pylint: disable=no-member -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api # pylint: disable=no-member +from .conftest import check_ocrmypdf, run_ocrmypdf, run_ocrmypdf_api # pylint: disable=redefined-outer-name diff --git a/tests/test_helpers.py b/tests/test_helpers.py index f0a5e4d0..7b885221 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -14,6 +14,8 @@ import pytest from ocrmypdf import helpers as helpers +from .conftest import running_in_docker + class TestSafeSymlink: def test_safe_symlink_link_self(self, tmp_path, caplog): @@ -58,9 +60,7 @@ def test_deprecated(): assert old_function() == 42 -skipif_docker = pytest.mark.skipif( - pytest.helpers.running_in_docker(), reason="fails on Docker" -) +skipif_docker = pytest.mark.skipif(running_in_docker(), reason="fails on Docker") class TestFileIsWritable: diff --git a/tests/test_hocrtransform.py b/tests/test_hocrtransform.py index 136c9a49..b0046e94 100644 --- a/tests/test_hocrtransform.py +++ b/tests/test_hocrtransform.py @@ -21,6 +21,8 @@ from ocrmypdf import hocrtransform from ocrmypdf._exec.tesseract import HOCR_TEMPLATE from ocrmypdf.helpers import check_pdf +from .conftest import check_ocrmypdf + def text_from_pdf(filename): output_string = StringIO() @@ -37,8 +39,6 @@ def text_from_pdf(filename): # pylint: disable=redefined-outer-name -check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=no-member - @pytest.fixture def blank_hocr(tmp_path): diff --git a/tests/test_image_input.py b/tests/test_image_input.py index 5efad8c0..ad738f84 100644 --- a/tests/test_image_input.py +++ b/tests/test_image_input.py @@ -14,8 +14,7 @@ from PIL import Image import ocrmypdf -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api +from .conftest import check_ocrmypdf, run_ocrmypdf_api @pytest.fixture diff --git a/tests/test_main.py b/tests/test_main.py index 33d45fba..4f5aedcf 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -24,12 +24,18 @@ from ocrmypdf.pdfa import file_claims_pdfa from ocrmypdf.pdfinfo import Colorspace, Encoding, PdfInfo from ocrmypdf.subprocess import get_version -# pytest.helpers is dynamic -# pylint: disable=no-member,redefined-outer-name +from .conftest import ( + check_ocrmypdf, + first_page_dimensions, + have_unpaper, + is_macos, + run_ocrmypdf, + run_ocrmypdf_api, + running_in_docker, + running_in_travis, +) -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api +# pylint: disable=redefined-outer-name RENDERERS = ['hocr', 'sandwich'] @@ -155,7 +161,7 @@ def test_maximum_options(renderer, output_type, resources, outpdf): resources / 'multipage.pdf', outpdf, '-d', - '-ci' if pytest.helpers.have_unpaper() else None, + '-ci' if have_unpaper() else None, '-f', '-k', '--oversample', @@ -208,7 +214,7 @@ def test_force_ocr_on_pdf_with_no_images(resources, no_outpdf): @pytest.mark.skipif( - pytest.helpers.is_macos() and pytest.helpers.running_in_travis(), + is_macos() and running_in_travis(), reason="takes too long to install language packs in Travis macOS homebrew", ) def test_german(resources, outdir): @@ -269,9 +275,7 @@ def test_input_file_not_found(caplog, no_outpdf): assert input_file in caplog.text -@pytest.mark.skipif( - os.name == 'nt' or pytest.helpers.running_in_docker(), reason="chmod" -) +@pytest.mark.skipif(os.name == 'nt' or running_in_docker(), reason="chmod") def test_input_file_not_readable(caplog, resources, outdir, no_outpdf): input_file = outdir / 'trivial.pdf' shutil.copy(resources / 'trivial.pdf', input_file) @@ -519,9 +523,6 @@ def test_form_xobject(resources, outpdf): @pytest.mark.parametrize('renderer', RENDERERS) def test_pagesize_consistency(renderer, resources, outpdf): - - first_page_dimensions = pytest.helpers.first_page_dimensions - infile = resources / '3small.pdf' before_dims = first_page_dimensions(infile) @@ -531,10 +532,10 @@ def test_pagesize_consistency(renderer, resources, outpdf): outpdf, '--pdf-renderer', renderer, - '--clean' if pytest.helpers.have_unpaper() else None, + '--clean' if have_unpaper() else None, '--deskew', '--remove-background', - '--clean-final' if pytest.helpers.have_unpaper() else None, + '--clean-final' if have_unpaper() else None, '--pages', '1', ) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index e6496d36..87df840a 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -24,19 +24,16 @@ from ocrmypdf.exceptions import ExitCode from ocrmypdf.pdfa import SRGB_ICC_PROFILE, file_claims_pdfa, generate_pdfa_ps from ocrmypdf.pdfinfo import PdfInfo +from .conftest import check_ocrmypdf, run_ocrmypdf + try: import fitz except ImportError: fitz = None -# pytest.helpers is dynamic -# pylint: disable=no-member pytestmark = pytest.mark.filterwarnings('ignore:.*XMLParser.*:DeprecationWarning') -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf - @pytest.mark.parametrize("output_type", ['pdfa', 'pdf']) def test_preserve_docinfo(output_type, resources, outpdf): diff --git a/tests/test_optimize.py b/tests/test_optimize.py index a319b812..96cb803b 100644 --- a/tests/test_optimize.py +++ b/tests/test_optimize.py @@ -19,7 +19,7 @@ from ocrmypdf._exec import jbig2enc, pngquant from ocrmypdf._exec.ghostscript import rasterize_pdf from ocrmypdf.helpers import Resolution -check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=e1101 +from .conftest import check_ocrmypdf needs_pngquant = pytest.mark.skipif( not pngquant.available(), reason="pngquant not installed" diff --git a/tests/test_pdfa.py b/tests/test_pdfa.py index d0c269ff..75b22a57 100644 --- a/tests/test_pdfa.py +++ b/tests/test_pdfa.py @@ -7,7 +7,7 @@ import pikepdf import pytest -check_ocrmypdf = pytest.helpers.check_ocrmypdf +from .conftest import check_ocrmypdf @pytest.mark.parametrize('optimize', (0, 3)) diff --git a/tests/test_preprocessing.py b/tests/test_preprocessing.py index 2fc81c10..593505e8 100644 --- a/tests/test_preprocessing.py +++ b/tests/test_preprocessing.py @@ -15,13 +15,7 @@ from ocrmypdf.helpers import Resolution from ocrmypdf.leptonica import Pix from ocrmypdf.pdfinfo import PdfInfo -# pytest.helpers is dynamic -# pylint: disable=no-member,redefined-outer-name - -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api - +from .conftest import check_ocrmypdf, have_unpaper, run_ocrmypdf, run_ocrmypdf_api RENDERERS = ['hocr', 'sandwich'] @@ -96,7 +90,7 @@ def test_exotic_image(pdf, renderer, output_type, resources, outdir): check_ocrmypdf( resources / pdf, outfile, - '-dc' if pytest.helpers.have_unpaper() else '-d', + '-dc' if have_unpaper() else '-d', '-v', '1', '--output-type', diff --git a/tests/test_rotation.py b/tests/test_rotation.py index b826a09e..cb7fcb7b 100644 --- a/tests/test_rotation.py +++ b/tests/test_rotation.py @@ -21,18 +21,16 @@ from ocrmypdf._plugin_manager import get_plugin_manager from ocrmypdf.helpers import Resolution from ocrmypdf.pdfinfo import PdfInfo -# pytest.helpers is dynamic -# pylint: disable=no-member -# pylint: disable=w0612 +from .conftest import check_ocrmypdf, run_ocrmypdf + +# pylintx: disable=unused-variable + pytestmark = pytest.mark.skipif( leptonica.get_leptonica_version() < 'leptonica-1.72', reason="Leptonica is too old, correlation doesn't work", ) -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf - RENDERERS = ['hocr', 'sandwich'] diff --git a/tests/test_stdio.py b/tests/test_stdio.py index cfd7f7b3..2e43cff5 100644 --- a/tests/test_stdio.py +++ b/tests/test_stdio.py @@ -15,11 +15,7 @@ import pytest from ocrmypdf.exceptions import ExitCode from ocrmypdf.helpers import check_pdf -# pytest.helpers is dynamic -# pylint: disable=no-member,redefined-outer-name - -run_ocrmypdf = pytest.helpers.run_ocrmypdf -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf +from .conftest import run_ocrmypdf def test_stdin(ocrmypdf_exec, resources, outpdf): diff --git a/tests/test_tesseract.py b/tests/test_tesseract.py index f7331e48..d4d1a521 100644 --- a/tests/test_tesseract.py +++ b/tests/test_tesseract.py @@ -17,10 +17,9 @@ from ocrmypdf import pdfinfo from ocrmypdf._exec import tesseract from ocrmypdf.exceptions import MissingDependencyError -# pylint: disable=no-member,redefined-outer-name +from .conftest import check_ocrmypdf, run_ocrmypdf -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf +# pylint: disable=redefined-outer-name @pytest.mark.parametrize('basename', ['graph_ocred.pdf', 'cardinal.pdf']) diff --git a/tests/test_unpaper.py b/tests/test_unpaper.py index eefe9852..72a32c5a 100644 --- a/tests/test_unpaper.py +++ b/tests/test_unpaper.py @@ -14,13 +14,9 @@ from ocrmypdf._plugin_manager import get_parser_options_plugins from ocrmypdf._validation import check_options from ocrmypdf.exceptions import ExitCode, MissingDependencyError -# pytest.helpers is dynamic -# pylint: disable=no-member,redefined-outer-name -# pylint: disable=w0612 +from .conftest import check_ocrmypdf, have_unpaper, run_ocrmypdf -check_ocrmypdf = pytest.helpers.check_ocrmypdf -run_ocrmypdf = pytest.helpers.run_ocrmypdf -have_unpaper = pytest.helpers.have_unpaper +# pylint: disable=redefined-outer-name def test_no_unpaper(resources, no_outpdf): diff --git a/tests/test_userunit.py b/tests/test_userunit.py index 6926d160..e3b9fe31 100644 --- a/tests/test_userunit.py +++ b/tests/test_userunit.py @@ -12,9 +12,7 @@ import pytest from ocrmypdf.exceptions import ExitCode from ocrmypdf.pdfinfo import PdfInfo -check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=no-member -run_ocrmypdf = pytest.helpers.run_ocrmypdf # pylint: disable=no-member -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api # pylint: disable=no-member +from .conftest import check_ocrmypdf, run_ocrmypdf, run_ocrmypdf_api # pylint: disable=redefined-outer-name diff --git a/tests/test_validation.py b/tests/test_validation.py index 7b2f1ead..81a4e5d5 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -19,7 +19,7 @@ from ocrmypdf.cli import get_parser from ocrmypdf.exceptions import BadArgsError, MissingDependencyError from ocrmypdf.pdfinfo import PdfInfo -run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api +from .conftest import run_ocrmypdf_api def make_opts_pm(input_file='a.pdf', output_file='b.pdf', language='eng', **kwargs):