Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2023
1 parent f524a35 commit 63b3103
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pytesseract/pytesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self):
'ALTO output not supported. Tesseract >= 4.1.0 required',
)


class URLNotSupported(EnvironmentError):
def __init__(self):
super().__init__(
Expand Down Expand Up @@ -218,8 +219,9 @@ def save(image):
with NamedTemporaryFile(prefix='tess_', delete=False) as f:
if isinstance(image, str):
if image.startswith('http:') or image.startswith('https:'):
if get_tesseract_version(cached=True) < TESSERACT_URL_VERSION\
or not has_libcurl(cached=True):
if get_tesseract_version(
cached=True,
) < TESSERACT_URL_VERSION or not has_libcurl(cached=True):
raise URLNotSupported()
yield f.name, image
else:
Expand Down Expand Up @@ -498,7 +500,7 @@ def has_libcurl():
)
except OSError:
raise TesseractNotFoundError()

return 'libcurl' in output.decode(DEFAULT_ENCODING)


Expand Down
10 changes: 6 additions & 4 deletions tests/pytesseract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
IS_PYTHON_3 = not IS_PYTHON_2

TESSERACT_VERSION = tuple(get_tesseract_version().release) # to skip tests
HAS_LIBCURL = has_libcurl() # to skip tests
HAS_LIBCURL = has_libcurl() # to skip tests

TESTS_DIR = path.dirname(path.abspath(__file__))
DATA_DIR = path.join(TESTS_DIR, 'data')
TESSDATA_DIR = path.join(TESTS_DIR, 'tessdata')
TEST_JPEG = path.join(DATA_DIR, 'test.jpg')
TEST_JPEG_URL = ('https://github.com/madmaze/pytesseract'
'/blob/master/tests/data/test.jpg?raw=true')
TEST_JPEG_URL = (
'https://github.com/madmaze/pytesseract'
'/blob/master/tests/data/test.jpg?raw=true'
)

pytestmark = pytest.mark.pytesseract # used marker for the module
string_type = unicode if IS_PYTHON_2 else str # noqa: 821
Expand Down Expand Up @@ -132,7 +134,7 @@ def test_image_to_string_with_image_type(test_file):
ids=['jpeg_url'],
)
def test_image_to_string_with_url(test_file):
# Tesseract-ocr supports image URLs from version 4.1.1
# Tesseract-ocr supports image URLs from version 4.1.1
# and must be built with libcurl.
if TESSERACT_VERSION < (4, 1, 1) or not HAS_LIBCURL:
pytest.skip('skip url test')
Expand Down

0 comments on commit 63b3103

Please sign in to comment.