Remove pytest_helpers_namespace
This commit is contained in:
@@ -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**
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
@@ -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
|
||||
@@ -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]
|
||||
|
||||
@@ -11,7 +11,7 @@ import pytest
|
||||
|
||||
import ocrmypdf
|
||||
|
||||
check_ocrmypdf = pytest.helpers.check_ocrmypdf
|
||||
from .conftest import check_ocrmypdf
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
+16
-15
@@ -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',
|
||||
)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -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))
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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']
|
||||
|
||||
|
||||
+1
-5
@@ -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):
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user