Fix validation of languages not using tesseract_env

And some related issues.
This commit is contained in:
James R. Barlow
2020-05-14 03:19:22 -07:00
parent d372f1f7fa
commit 12a2f78c4d
3 changed files with 8 additions and 7 deletions
+2 -2
View File
@@ -84,12 +84,12 @@ def check_options_languages(options):
options.language = options.language[0].split('+')
languages = set(options.language)
if not languages.issubset(tesseract.languages()):
if not languages.issubset(tesseract.languages(options.tesseract_env)):
msg = (
"The installed version of tesseract does not have language "
"data for the following requested languages: \n"
)
for lang in languages - tesseract.languages():
for lang in languages - tesseract.languages(options.tesseract_env):
msg += lang + '\n'
raise MissingDependencyError(msg)
+2 -1
View File
@@ -241,7 +241,7 @@ def run_ocrmypdf_api(input_file, output_file, *args, env=None):
[str(input_file), str(output_file)]
+ [str(arg) for arg in args if arg is not None]
)
api.check_options(options)
if env:
options.tesseract_env = env.copy()
options.tesseract_env['_OCRMYPDF_TEST_INFILE'] = os.fspath(input_file)
@@ -252,6 +252,7 @@ def run_ocrmypdf_api(input_file, output_file, *args, env=None):
if options.tesseract_env:
assert all(isinstance(v, (str, bytes)) for v in options.tesseract_env.values())
api.check_options(options)
return api.run_pipeline(options, plugin_manager=None, api=False)
+4 -4
View File
@@ -186,10 +186,10 @@ def test_tesseract_missing_tessdata(resources, no_outpdf, tmpdir):
env = os.environ.copy()
env['TESSDATA_PREFIX'] = os.fspath(tmpdir)
returncode = run_ocrmypdf_api(
resources / 'graph.pdf', no_outpdf, '-v', '1', '--skip-text', env=env
)
assert returncode == ExitCode.missing_dependency
with pytest.raises(MissingDependencyError):
run_ocrmypdf_api(
resources / 'graph.pdf', no_outpdf, '-v', '1', '--skip-text', env=env
)
def test_invalid_input_pdf(resources, no_outpdf):