Skip to content

Commit

Permalink
rename module (#7)
Browse files Browse the repository at this point in the history
* build as unstructured.pytessseract

* rename module

* add

* fix setup config

* update workflow
  • Loading branch information
badGarnet authored Sep 5, 2023
1 parent c3da6a5 commit a81eeb5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
TOX_TESTENV_PASSENV: PY_COLORS

- name: Test pytesseract package installation
run: pip install -U git+${{ github.server_url }}/${{ github.repository }} && pip show pytesseract && python -c 'import pytesseract'
run: pip install -U git+${{ github.server_url }}/${{ github.repository }} && pip show unstructured_pytesseract && python -c 'import unstructured_pytesseract'
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pytesseract
version = attr: pytesseract.__version__
name = unstructured_pytesseract
version = attr: unstructured_pytesseract.__version__
author = Samuel Hoffstaetter
author_email = [email protected]
maintainer = Matthias Lee
Expand Down Expand Up @@ -34,7 +34,7 @@ python_requires = >=3.8
[options.entry_points]
console_scripts =
pytesseract = pytesseract.pytesseract:main
pytesseract = pytesseract_unstructured.pytesseract:main
[options.packages.find]
exclude =
Expand Down
63 changes: 33 additions & 30 deletions tests/pytesseract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

import pytest

from pytesseract import ALTONotSupported
from pytesseract import get_languages
from pytesseract import get_tesseract_version
from pytesseract import image_to_alto_xml
from pytesseract import image_to_boxes
from pytesseract import image_to_data
from pytesseract import image_to_osd
from pytesseract import image_to_pdf_or_hocr
from pytesseract import image_to_string
from pytesseract import Output
from pytesseract import run_and_get_multiple_output
from pytesseract import TesseractNotFoundError
from pytesseract import TSVNotSupported
from pytesseract.pytesseract import file_to_dict
from pytesseract.pytesseract import numpy_installed
from pytesseract.pytesseract import pandas_installed
from pytesseract.pytesseract import prepare
from unstructured_pytesseract import ALTONotSupported
from unstructured_pytesseract import get_languages
from unstructured_pytesseract import get_tesseract_version
from unstructured_pytesseract import image_to_alto_xml
from unstructured_pytesseract import image_to_boxes
from unstructured_pytesseract import image_to_data
from unstructured_pytesseract import image_to_osd
from unstructured_pytesseract import image_to_pdf_or_hocr
from unstructured_pytesseract import image_to_string
from unstructured_pytesseract import Output
from unstructured_pytesseract import run_and_get_multiple_output
from unstructured_pytesseract import TesseractNotFoundError
from unstructured_pytesseract import TSVNotSupported
from unstructured_pytesseract.pytesseract import file_to_dict
from unstructured_pytesseract.pytesseract import numpy_installed
from unstructured_pytesseract.pytesseract import pandas_installed
from unstructured_pytesseract.pytesseract import prepare

if numpy_installed:
import numpy as np
Expand Down Expand Up @@ -379,18 +379,21 @@ def test_wrong_prepare_type(obj):
)
def test_wrong_tesseract_cmd(monkeypatch, test_file, test_path):
"""Test wrong or missing tesseract command."""
import pytesseract
import unstructured_pytesseract

monkeypatch.setattr('pytesseract.pytesseract.tesseract_cmd', test_path)
monkeypatch.setattr(
'unstructured_pytesseract.pytesseract.tesseract_cmd',
test_path,
)

with pytest.raises(TesseractNotFoundError):
pytesseract.get_languages.__wrapped__()
unstructured_pytesseract.get_languages.__wrapped__()

with pytest.raises(TesseractNotFoundError):
pytesseract.get_tesseract_version.__wrapped__()
unstructured_pytesseract.get_tesseract_version.__wrapped__()

with pytest.raises(TesseractNotFoundError):
pytesseract.image_to_string(test_file)
unstructured_pytesseract.image_to_string(test_file)


def test_main_not_found_cases(
Expand All @@ -400,29 +403,29 @@ def test_main_not_found_cases(
test_invalid_file,
):
"""Test wrong or missing tesseract command in main."""
import pytesseract
import unstructured_pytesseract

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

monkeypatch.setattr(
'pytesseract.pytesseract.tesseract_cmd',
'unstructured_pytesseract.pytesseract.tesseract_cmd',
'wrong_tesseract',
)
monkeypatch.setattr('sys.argv', ['', test_file])
assert pytesseract.pytesseract.main() == 1
assert unstructured_pytesseract.pytesseract.main() == 1
assert (
"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', [''])
assert pytesseract.pytesseract.main() == 2
assert unstructured_pytesseract.pytesseract.main() == 2
assert 'Usage: pytesseract [-l lang] input_file' in capsys.readouterr().err


Expand All @@ -433,17 +436,17 @@ def test_main_not_found_cases(
)
def test_proper_oserror_exception_handling(monkeypatch, test_file, test_path):
""" "Test for bubbling up OSError exceptions."""
import pytesseract
import unstructured_pytesseract

monkeypatch.setattr(
'pytesseract.pytesseract.tesseract_cmd',
'unstructured_pytesseract.pytesseract.tesseract_cmd',
test_path,
)

with pytest.raises(
TesseractNotFoundError if IS_PYTHON_2 and test_path else OSError,
):
pytesseract.image_to_string(test_file)
unstructured_pytesseract.image_to_string(test_file)


DEFAULT_LANGUAGES = ('fra', 'eng', 'osd')
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit a81eeb5

Please sign in to comment.