Skip to content

Commit

Permalink
Rewrite safer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Miroito committed Jul 30, 2022
1 parent e4e7093 commit 7837af5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/unit_tests/services_tests/test_ocr_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from pathlib import Path

from mealie.services.ocr.pytesseract import OCR
from mealie.services.ocr.pytesseract import OcrService

ocr_service = OcrService()


def test_image_to_string():
result = OCR.image_to_string(open(Path("tests/data/images/test-ocr.png"), "rb"))
expected_result = open(Path("tests/data/text/test-ocr.txt"))
assert result == expected_result.read()
with open(Path("tests/data/images/test-ocr.png"), "rb") as image:
result = ocr_service.image_to_string(image)
with open(Path("tests/data/text/test-ocr.txt"), "r", encoding="utf-8") as expected_result:
assert result == expected_result.read()


def test_image_to_tsv():
result = OCR.image_to_tsv(open(Path("tests/data/images/test-ocr.png"), "rb").read())
expected_result = open(Path("tests/data/text/test-ocr.tsv"))
assert result == expected_result.read()
with open(Path("tests/data/images/test-ocr.png"), "rb") as image:
result = ocr_service.image_to_tsv(image.read())
with open(Path("tests/data/text/test-ocr.tsv"), "r", encoding="utf-8") as expected_result:
assert result == expected_result.read()

0 comments on commit 7837af5

Please sign in to comment.