tests: convert all uses of multipage.pdf to fixture
This commit is contained in:
+6
-1
@@ -44,7 +44,7 @@ TESTS_ROOT = Path(__file__).parent.resolve()
|
||||
PROJECT_ROOT = TESTS_ROOT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture(scope="session")
|
||||
def resources() -> Path:
|
||||
return Path(TESTS_ROOT) / 'resources'
|
||||
|
||||
@@ -78,6 +78,11 @@ def no_outpdf(tmp_path) -> Path:
|
||||
return tmp_path / 'no_output.pdf'
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def multipage(resources):
|
||||
return resources / 'multipage.pdf'
|
||||
|
||||
|
||||
def check_ocrmypdf(input_file: Path, output_file: Path, *args) -> Path:
|
||||
"""Run ocrmypdf and confirm that a valid plausible PDF was created."""
|
||||
api_args = [str(input_file), str(output_file)] + [
|
||||
|
||||
@@ -14,9 +14,9 @@ from .conftest import run_ocrmypdf_api
|
||||
|
||||
@pytest.mark.skipif(True, reason="--use-threads is currently default")
|
||||
@pytest.mark.skipif(os.name == 'nt', reason="Windows doesn't have SIGKILL")
|
||||
def test_simulate_oom_killer(resources, no_outpdf):
|
||||
def test_simulate_oom_killer(multipage, no_outpdf):
|
||||
exitcode = run_ocrmypdf_api(
|
||||
resources / 'multipage.pdf',
|
||||
multipage,
|
||||
no_outpdf,
|
||||
'--force-ocr',
|
||||
'--plugin',
|
||||
|
||||
+3
-4
@@ -7,11 +7,10 @@ import os
|
||||
import shutil
|
||||
from math import isclose
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, run
|
||||
from subprocess import run
|
||||
from unittest.mock import patch
|
||||
|
||||
import pikepdf
|
||||
import PIL
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
@@ -153,9 +152,9 @@ def test_skip_big(resources, outpdf):
|
||||
|
||||
@pytest.mark.parametrize('renderer', RENDERERS)
|
||||
@pytest.mark.parametrize('output_type', ['pdf', 'pdfa'])
|
||||
def test_maximum_options(renderer, output_type, resources, outpdf):
|
||||
def test_maximum_options(renderer, output_type, multipage, outpdf):
|
||||
check_ocrmypdf(
|
||||
resources / 'multipage.pdf',
|
||||
multipage,
|
||||
outpdf,
|
||||
'-d',
|
||||
'-ci' if have_unpaper() else None,
|
||||
|
||||
@@ -27,10 +27,15 @@ needs_jbig2enc = pytest.mark.skipif(
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def palette(resources):
|
||||
return resources / 'palette.pdf'
|
||||
|
||||
|
||||
@needs_pngquant
|
||||
@pytest.mark.parametrize('pdf', ['multipage.pdf', 'palette.pdf'])
|
||||
def test_basic(resources, pdf, outpdf):
|
||||
infile = resources / pdf
|
||||
@pytest.mark.parametrize('pdf', ['multipage', 'palette'])
|
||||
def test_basic(multipage, palette, pdf, outpdf):
|
||||
infile = multipage if pdf == 'multipage' else palette
|
||||
opt.main(infile, outpdf, level=3)
|
||||
|
||||
assert 0.98 * Path(outpdf).stat().st_size <= Path(infile).stat().st_size
|
||||
|
||||
@@ -48,10 +48,9 @@ def test_nonmonotonic_warning(caplog):
|
||||
assert 'out of order' in caplog.text
|
||||
|
||||
|
||||
def test_limited_pages(resources, outpdf):
|
||||
multi = resources / 'multipage.pdf'
|
||||
def test_limited_pages(multipage, outpdf):
|
||||
ocrmypdf.ocr(
|
||||
multi,
|
||||
multipage,
|
||||
outpdf,
|
||||
pages='5-6',
|
||||
optimize=0,
|
||||
|
||||
Reference in New Issue
Block a user