Skip to content

Commit

Permalink
fix: handle tesseract error on invalid tessdata
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDaG committed Nov 22, 2024
1 parent b559558 commit 9955bc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pytesseract/pytesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,8 @@ def get_languages(config=''):
except OSError:
raise TesseractNotFoundError()

# tesseract 3.x
if result.returncode not in (0, 1):
raise TesseractNotFoundError()
if result.returncode != 0 :
raise TesseractError(result.returncode, "--list-langs failed")

languages = []
if result.stdout:
Expand Down
15 changes: 10 additions & 5 deletions tests/pytesseract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from pytesseract import Output
from pytesseract import run_and_get_multiple_output
from pytesseract import TesseractNotFoundError
from pytesseract import TesseractError
from pytesseract import TSVNotSupported
from pytesseract.pytesseract import file_to_dict
from pytesseract.pytesseract import numpy_installed
Expand Down Expand Up @@ -467,12 +468,16 @@ def test_proper_oserror_exception_handling(monkeypatch, test_file, test_path):
],
)
def test_get_languages(test_config, expected):
result = get_languages.__wrapped__(test_config)
if not result:
assert result == []
try :
result = get_languages.__wrapped__(test_config)
if not result:
assert result == []

for lang in expected:
assert lang in result
except TesseractError:
assert expected == ()

for lang in expected:
assert lang in result


@pytest.mark.parametrize(
Expand Down

0 comments on commit 9955bc0

Please sign in to comment.