From 7837af5e601bd5090b015fdb30fefd3594ee450b Mon Sep 17 00:00:00 2001 From: Miroito Date: Sat, 30 Jul 2022 11:49:47 +0200 Subject: [PATCH] Rewrite safer tests --- .../services_tests/test_ocr_service.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/services_tests/test_ocr_service.py b/tests/unit_tests/services_tests/test_ocr_service.py index e5e88e1c11a..6666ed88588 100644 --- a/tests/unit_tests/services_tests/test_ocr_service.py +++ b/tests/unit_tests/services_tests/test_ocr_service.py @@ -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()