Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
kristapratico committed Aug 12, 2020
commit 1856542185800dae8cf1b7a701cebbaadfec7528
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def __repr__(self):
)[:1024]


class FormTableCell(object):
class FormTableCell(object): # pylint:disable=too-many-instance-attributes
"""Represents a cell contained in a table recognized from the input document.

:ivar str text: Text content of the cell.
Expand Down
4 changes: 2 additions & 2 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def bounding_box():
@pytest.fixture
def form_word(bounding_box):
model = _models.FormWord(text="Word", bounding_box=bounding_box[0], confidence=0.5, page_number=1)
model_repr = "FormWord(text=Word, bounding_box={}, confidence=0.5, page_number=1)".format(bounding_box[1])[:1024]
model_repr = "FormWord(text=Word, bounding_box={}, confidence=0.5, page_number=1, kind=word)".format(bounding_box[1])[:1024]
assert repr(model) == model_repr
return model, model_repr


@pytest.fixture
def form_line(bounding_box, form_word):
model = _models.FormLine(text="Word Word", bounding_box=bounding_box[0], words=[form_word[0], form_word[0]], page_number=1)
model_repr = "FormLine(text=Word Word, bounding_box={}, words=[{}, {}], page_number=1)".format(bounding_box[1], form_word[1], form_word[1])[:1024]
model_repr = "FormLine(text=Word Word, bounding_box={}, words=[{}, {}], page_number=1, kind=line)".format(bounding_box[1], form_word[1], form_word[1])[:1024]
assert repr(model) == model_repr
return model, model_repr

Expand Down
16 changes: 11 additions & 5 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ def assertFormPagesTransformCorrect(self, pages, actual_read, page_result=None,
if not page.lines and not actual_page.lines:
continue
for p, a in zip(page.lines, actual_page.lines):
self.assertEqual(p.kind, "line")
self.assertEqual(p.text, a.text)
self.assertBoundingBoxTransformCorrect(p.bounding_box, a.bounding_box)
for wp, wa, in zip(p.words, a.words):
self.assertEqual(wp.kind, "word")
self.assertEqual(wp.text, wa.text)
self.assertEqual(wp.confidence, wa.confidence if wa.confidence is not None else 1.0)
self.assertBoundingBoxTransformCorrect(wp.bounding_box, wa.bounding_box)
Expand All @@ -204,13 +206,14 @@ def assertBoundingBoxTransformCorrect(self, box, actual):
def assertFieldElementsTransFormCorrect(self, field_elements, actual_elements, read_result):
if field_elements is None and actual_elements is None:
return
for receipt, actual in zip(field_elements, actual_elements):
for element, actual in zip(field_elements, actual_elements):
nums = [int(s) for s in re.findall(r'\d+', actual)]
read, line, word = nums[0:3]
text_element = read_result[read].lines[line].words[word]
self.assertEqual(receipt.text, text_element.text)
self.assertEqual(receipt.confidence, text_element.confidence if text_element.confidence is not None else 1.0)
self.assertBoundingBoxTransformCorrect(receipt.bounding_box, text_element.bounding_box)
actual_element = read_result[read].lines[line].words[word]
self.assertEqual(element.text, actual_element.text)
self.assertEqual(element.confidence, actual_element.confidence if actual_element.confidence is not None else 1.0)
self.assertEqual(element.kind, "word")
self.assertBoundingBoxTransformCorrect(element.bounding_box, actual_element.bounding_box)

def assertLabeledFormFieldDictTransformCorrect(self, form_fields, actual_fields, read_results=None):
if actual_fields is None:
Expand Down Expand Up @@ -368,7 +371,9 @@ def assertFormPagesHasValues(self, pages):
self.assertIsNotNone(line.text)
self.assertIsNotNone(line.page_number)
self.assertBoundingBoxHasPoints(line.bounding_box)
self.assertEqual(line.kind, "line")
for word in line.words:
self.assertEqual(word.kind, "word")
self.assertFormWordHasValues(word, page.page_number)

if page.tables:
Expand All @@ -386,6 +391,7 @@ def assertFormPagesHasValues(self, pages):
self.assertFieldElementsHasValues(cell.field_elements, page.page_number)

def assertFormWordHasValues(self, word, page_number):
self.assertEqual(word.kind, "word")
self.assertIsNotNone(word.confidence)
self.assertIsNotNone(word.text)
self.assertBoundingBoxHasPoints(word.bounding_box)
Expand Down