Skip to content

Commit

Permalink
Merge pull request #505 from madmaze/uncached_tesseract_version_call
Browse files Browse the repository at this point in the history
Add uncached tesseract version call
  • Loading branch information
int3l committed Aug 25, 2023
2 parents d33f02d + 2f24cd1 commit 6232e97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pytesseract/pytesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def timeout_manager(proc, seconds=None):
def run_once(func):
@wraps(func)
def wrapper(*args, **kwargs):
if wrapper._result is wrapper:
if not kwargs.pop('cached', False) or wrapper._result is wrapper:
wrapper._result = func(*args, **kwargs)
return wrapper._result

Expand Down Expand Up @@ -465,7 +465,7 @@ def image_to_alto_xml(
Returns the result of a Tesseract OCR run on the provided image to ALTO XML
"""

if get_tesseract_version() < TESSERACT_ALTO_VERSION:
if get_tesseract_version(cached=True) < TESSERACT_ALTO_VERSION:
raise ALTONotSupported()

config = f'-c tessedit_create_alto=1 {config.strip()}'
Expand Down Expand Up @@ -528,7 +528,7 @@ def image_to_data(
and other information. Requires Tesseract 3.05+
"""

if get_tesseract_version() < TESSERACT_MIN_VERSION:
if get_tesseract_version(cached=True) < TESSERACT_MIN_VERSION:
raise TSVNotSupported()

config = f'-c tessedit_create_tsv=1 {config.strip()}'
Expand Down Expand Up @@ -587,4 +587,4 @@ def main():


if __name__ == '__main__':
exit(main())
raise SystemExit(main())
9 changes: 5 additions & 4 deletions tests/pytesseract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ def test_main_not_found_cases(

monkeypatch.setattr('sys.argv', ['', test_invalid_file])
assert pytesseract.pytesseract.main() == 1
captured_stderr = capsys.readouterr().err
captured = capsys.readouterr()
assert (
'No such file or directory' in captured_stderr
and test_invalid_file in captured_stderr
'No such file or directory' in captured.err
and repr(test_invalid_file) in captured.err
)

monkeypatch.setattr(
Expand All @@ -377,7 +377,8 @@ def test_main_not_found_cases(
monkeypatch.setattr('sys.argv', ['', test_file])
assert pytesseract.pytesseract.main() == 1
assert (
"is not installed or it's not in your PATH" in capsys.readouterr().err
"wrong_tesseract is not installed or it's not in your PATH. "
'See README file for more information.' in capsys.readouterr().err
)

monkeypatch.setattr('sys.argv', [''])
Expand Down

0 comments on commit 6232e97

Please sign in to comment.