From 450635d9ba58a6386de83298a83d444e522d2269 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Mon, 10 Jan 2022 12:34:42 -0300 Subject: [PATCH] Adding the tests to the new ocr methods. --- api/ocr/features/ocr.feature | 13 ++++++++ api/ocr/features/steps/steps.py | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/api/ocr/features/ocr.feature b/api/ocr/features/ocr.feature index e69de29..1908fcd 100644 --- a/api/ocr/features/ocr.feature +++ b/api/ocr/features/ocr.feature @@ -0,0 +1,13 @@ +Feature: The OCR API client +# ======================== OCR method ======================== + Scenario: Using the OCR standard method + Given the OCR client + When the OCR method is called + Then there must be an dictionary as a return + +# ======================== Strings method ======================== + Scenario: Using the Strings method + Given the OCR client + And an OCR object + When the Strings method is called + Then there must be a list of dictionaries with the content read and other info \ No newline at end of file diff --git a/api/ocr/features/steps/steps.py b/api/ocr/features/steps/steps.py index e69de29..1c3b25a 100644 --- a/api/ocr/features/steps/steps.py +++ b/api/ocr/features/steps/steps.py @@ -0,0 +1,54 @@ +from behave import * +from cli import Ocr +# ========================== OCR Standard method ========================== +@given(u'the OCR client') +def step_impl(context): + context.client = Ocr() + +@when(u'the OCR method is called') +def step_impl(context): + context.ocr_return = context.client.ocr({ + "X": 0, + "Y": 0, + "H": 400, + "W": 400, + "Resizeh": 1200, + "Resizew": 1200, + "Sharpen": 1, + "Tempfile": "some_test.jpg", + "Src": "ss", + "AddRects": True, + "Gray": True, + "Lang": "por" + }) + +@then(u'there must be an dictionary as a return') +def step_impl(context): + assert "Layout" in context.ocr_return, "An error ocurred during the optical character recognition process." + + +# ========================== OCR Strings method ========================== +@given(u'an OCR object') +def step_impl(context): + context.ocr_return = context.client.ocr({ + "X": 0, + "Y": 0, + "H": 400, + "W": 400, + "Resizeh": 1200, + "Resizew": 1200, + "Sharpen": 1, + "Tempfile": "some_test.jpg", + "Src": "ss", + "AddRects": True, + "Gray": True, + "Lang": "por" + }) + +@when(u'the Strings method is called') +def step_impl(context): + context.strings_return = context.client.strings(context.ocr_return) + +@then(u'there must be a list of dictionaries with the content read and other info') +def step_impl(context): + assert "CONTENT" in context.strings_return[0], "Something went wrong with the strings method." \ No newline at end of file