Convert one test to use API

This commit is contained in:
James R. Barlow
2019-05-22 23:53:48 -07:00
parent a139e64c67
commit 5cecb3ecb4
2 changed files with 25 additions and 17 deletions
+17
View File
@@ -18,6 +18,7 @@
import os
import platform
import sys
from contextlib import contextmanager
from pathlib import Path
from subprocess import PIPE, run
@@ -115,6 +116,22 @@ def spoof(tmpdir_factory, **kwargs):
return env
@pytest.helpers.register
@contextmanager
def os_environ(new_env):
old_env = os.environ.copy()
for k, v in new_env.items():
os.environ[k] = v
yield
new_keys = set(os.environ.copy()) - set(old_env)
for k in new_keys:
del os.environ[k]
for k in old_env:
os.environ[k] = old_env[k]
assert os.environ.copy() == old_env
@pytest.fixture(scope='session')
def spoof_tesseract_noop(tmpdir_factory):
return spoof(tmpdir_factory, tesseract='tesseract_noop.py')
+8 -17
View File
@@ -19,9 +19,10 @@ import os
import pytest
from ocrmypdf import ocrmypdf
import pikepdf
check_ocrmypdf = pytest.helpers.check_ocrmypdf
os_environ = pytest.helpers.os_environ
def test_no_glyphless_weave(resources, outdir):
@@ -34,26 +35,16 @@ def test_no_glyphless_weave(resources, outdir):
env = os.environ.copy()
env['_OCRMYPDF_MAX_REPLACE_PAGES'] = '2'
check_ocrmypdf(
outdir / 'test.pdf',
outdir / 'out.pdf',
'--deskew',
'--tesseract-timeout',
'0',
env=env,
)
with os_environ(env):
ocrmypdf(
outdir / 'test.pdf', outdir / 'out.pdf', deskew=True, tesseract_timeout=0
)
@pytest.helpers.needs_pdfminer
def test_links(resources, outpdf):
check_ocrmypdf(
resources / 'link.pdf',
outpdf,
'--redo-ocr',
'--oversample',
'200',
'--output-type',
'pdf',
ocrmypdf(
resources / 'link.pdf', outpdf, redo_ocr=True, oversample=200, output_type='pdf'
)
pdf = pikepdf.open(outpdf)
p1 = pdf.pages[0]