Skip to content

Commit

Permalink
Add default value of None for optional parameters, and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
holtskinner committed Jul 11, 2024
1 parent 99665f2 commit 42f4b8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions google/cloud/documentai_toolbox/wrappers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class Entity:
page_offset: dataclasses.InitVar[Optional[int]] = 0

type_: str = dataclasses.field(init=False)
mention_text: Optional[str] = dataclasses.field(init=False, default="")
normalized_text: Optional[str] = dataclasses.field(init=False, default="")
mention_text: Optional[str] = dataclasses.field(init=False, default=None)
normalized_text: Optional[str] = dataclasses.field(init=False, default=None)

# Not populated in Classifier output
start_page: Optional[int] = dataclasses.field(init=False)
start_page: Optional[int] = dataclasses.field(init=False, default=None)
# Only Populated for Splitter Output
end_page: Optional[int] = dataclasses.field(init=False)
end_page: Optional[int] = dataclasses.field(init=False, default=None)

_image: Optional[Image.Image] = dataclasses.field(init=False, default=None)

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ def test_entities_from_shards_classifier(get_bytes_classifier_mock):
assert actual[0].type_ == "computer_vision"
assert round(actual[0].documentai_object.confidence, 8) == 0.47925246
assert actual[0].documentai_object.id == "0"
assert actual[1].type_ == "crypto"
assert round(actual[1].documentai_object.confidence, 8) == 0.0433604
assert actual[1].documentai_object.id == "1"
assert actual[2].type_ == "med_tech"
assert round(actual[2].documentai_object.confidence, 8) == 0.26732057
assert actual[2].documentai_object.id == "2"
assert actual[3].type_ == "other"
assert round(actual[3].documentai_object.confidence, 8) == 0.2100666
assert actual[3].documentai_object.id == "3"


@mock.patch("google.cloud.documentai_toolbox.wrappers.document.documentai")
Expand Down

0 comments on commit 42f4b8c

Please sign in to comment.