From f55732e8f0ddb40071a97d8c745ebc1c2f3f7b01 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Dec 2023 17:00:53 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytesseract/pytesseract.py | 8 +++++--- tests/pytesseract_test.py | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pytesseract/pytesseract.py b/pytesseract/pytesseract.py index 769a514e..a95230d0 100644 --- a/pytesseract/pytesseract.py +++ b/pytesseract/pytesseract.py @@ -124,6 +124,7 @@ def __init__(self): 'ALTO output not supported. Tesseract >= 4.1.0 required', ) + class URLNotSupported(EnvironmentError): def __init__(self): super().__init__( @@ -217,8 +218,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: @@ -497,7 +499,7 @@ def has_libcurl(): ) except OSError: raise TesseractNotFoundError() - + return 'libcurl' in output.decode(DEFAULT_ENCODING) diff --git a/tests/pytesseract_test.py b/tests/pytesseract_test.py index aef174f1..d9d111d6 100644 --- a/tests/pytesseract_test.py +++ b/tests/pytesseract_test.py @@ -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 @@ -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')