Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[formrecognizer] Capitalize enum values #12540

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.0.0b5 (Unreleased)

**Breaking Changes**

- Values are now capitalized for enums `FormContentType`, `LengthUnit`, `TrainingStatus`, and `CustomFormModelStatus`

## 1.0.0b4 (2020-07-07)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,36 @@ class LengthUnit(str, Enum):
For images, the unit is "pixel". For PDF, the unit is "inch".
"""

pixel = "pixel"
inch = "inch"
PIXEL = "pixel"
INCH = "inch"


class TrainingStatus(str, Enum):
"""Status of the training operation.
"""

succeeded = "succeeded"
partially_succeeded = "partiallySucceeded"
failed = "failed"
SUCCEEDED = "succeeded"
PARTIALLY_SUCCEEDED = "partiallySucceeded"
FAILED = "failed"


class CustomFormModelStatus(str, Enum):
"""Status indicating the model's readiness for use.
"""

creating = "creating"
ready = "ready"
invalid = "invalid"
CREATING = "creating"
READY = "ready"
INVALID = "invalid"


class FormContentType(str, Enum):
"""Content type for upload
"""

application_pdf = "application/pdf" #: Content Type 'application/pdf'.
image_jpeg = "image/jpeg" #: Content Type 'image/jpeg'.
image_png = "image/png" #: Content Type 'image/png'.
image_tiff = "image/tiff" #: Content Type 'image/tiff'.
APPLICATION_PDF = "application/pdf" #: Content Type 'application/pdf'.
IMAGE_JPEG = "image/jpeg" #: Content Type 'image/jpeg'.
IMAGE_PNG = "image/png" #: Content Type 'image/png'.
IMAGE_TIFF = "image/tiff" #: Content Type 'image/tiff'.


class Point(namedtuple("Point", "x y")):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_passing_enum_content_type(self, client):
myfile = fd.read()
poller = client.begin_recognize_content(
myfile,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
result = poller.result()
self.assertIsNotNone(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_passing_enum_content_type(self, client):
myfile = fd.read()
poller = await client.begin_recognize_content(
myfile,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
result = await poller.result()
self.assertIsNotNone(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_custom_form_unlabeled(self, client, container_sas_url):
poller = fr_client.begin_recognize_custom_forms(
model.model_id,
stream,
content_type=FormContentType.image_jpeg
content_type=FormContentType.IMAGE_JPEG
)
form = poller.result()

Expand All @@ -158,7 +158,7 @@ def test_custom_form_multipage_unlabeled(self, client, container_sas_url):
poller = fr_client.begin_recognize_custom_forms(
model.model_id,
stream,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
forms = poller.result()

Expand Down Expand Up @@ -188,7 +188,7 @@ def test_custom_form_labeled(self, client, container_sas_url):
with open(self.form_jpg, "rb") as fd:
myfile = fd.read()

poller = fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg)
poller = fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.IMAGE_JPEG)
form = poller.result()

self.assertEqual(form[0].form_type, "form-"+model.model_id)
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_custom_form_multipage_labeled(self, client, container_sas_url):
poller = fr_client.begin_recognize_custom_forms(
model.model_id,
myfile,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
forms = poller.result()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def test_custom_form_unlabeled(self, client, container_sas_url):
with open(self.form_jpg, "rb") as fd:
myfile = fd.read()

poller = await fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg)
poller = await fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.IMAGE_JPEG)
form = await poller.result()
self.assertEqual(form[0].form_type, "form-0")
self.assertFormPagesHasValues(form[0].pages)
Expand All @@ -165,7 +165,7 @@ async def test_custom_form_multipage_unlabeled(self, client, container_sas_url):
poller = await fr_client.begin_recognize_custom_forms(
model.model_id,
myfile,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
forms = await poller.result()

Expand All @@ -192,7 +192,7 @@ async def test_custom_form_labeled(self, client, container_sas_url):
with open(self.form_jpg, "rb") as fd:
myfile = fd.read()

poller = await fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg)
poller = await fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.IMAGE_JPEG)
form = await poller.result()

self.assertEqual(form[0].form_type, "form-"+model.model_id)
Expand Down Expand Up @@ -220,7 +220,7 @@ async def test_custom_form_multipage_labeled(self, client, container_sas_url):
poller = await fr_client.begin_recognize_custom_forms(
model.model_id,
myfile,
content_type=FormContentType.application_pdf
content_type=FormContentType.APPLICATION_PDF
)
forms = await poller.result()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_passing_enum_content_type(self, client):
myfile = fd.read()
poller = client.begin_recognize_receipts(
myfile,
content_type=FormContentType.image_png
content_type=FormContentType.IMAGE_PNG
)
result = poller.result()
self.assertIsNotNone(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def test_passing_enum_content_type(self, client):
myfile = fd.read()
poller = await client.begin_recognize_receipts(
myfile,
content_type=FormContentType.image_png
content_type=FormContentType.IMAGE_PNG
)
result = await poller.result()
self.assertIsNotNone(result)
Expand Down
8 changes: 4 additions & 4 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def page_range():

@pytest.fixture
def form_page(form_table, form_line):
model = _models.FormPage(page_number=1, text_angle=180, width=5, height=5.5, unit=_models.LengthUnit.pixel, tables=[form_table[0]], lines=[form_line[0]])
model = _models.FormPage(page_number=1, text_angle=180, width=5, height=5.5, unit=_models.LengthUnit.PIXEL, tables=[form_table[0]], lines=[form_line[0]])
model_repr = "FormPage(page_number=1, text_angle=180, width=5, height=5.5, unit=pixel, tables=[{}], lines=[{}])".format(
form_table[1], form_line[1]
)[:1024]
Expand Down Expand Up @@ -118,7 +118,7 @@ def form_recognizer_error():

@pytest.fixture
def training_document_info(form_recognizer_error):
model = _models.TrainingDocumentInfo(document_name="document_name", status=_models.TrainingStatus.partially_succeeded, page_count=5, errors=[form_recognizer_error[0]])
model = _models.TrainingDocumentInfo(document_name="document_name", status=_models.TrainingStatus.PARTIALLY_SUCCEEDED, page_count=5, errors=[form_recognizer_error[0]])
model_repr = "TrainingDocumentInfo(document_name=document_name, status=partiallySucceeded, page_count=5, errors=[{}])".format(form_recognizer_error[1])[:1024]
assert repr(model) == model_repr
return model, model_repr
Expand All @@ -137,7 +137,7 @@ def test_recognized_form(self, form_field_one, page_range, form_page):
def test_custom_form_model(self, custom_form_sub_model, form_recognizer_error, training_document_info):
model = _models.CustomFormModel(
model_id=1,
status=_models.CustomFormModelStatus.creating,
status=_models.CustomFormModelStatus.CREATING,
training_started_on=datetime.datetime(1, 1, 1),
training_completed_on=datetime.datetime(1, 1, 1),
submodels=[custom_form_sub_model[0], custom_form_sub_model[0]],
Expand All @@ -154,7 +154,7 @@ def test_custom_form_model(self, custom_form_sub_model, form_recognizer_error, t

def test_custom_form_model_info(self):
model = _models.CustomFormModelInfo(
model_id=1, status=_models.CustomFormModelStatus.ready, training_started_on=datetime.datetime(1, 1, 1), training_completed_on=datetime.datetime(1, 1, 1)
model_id=1, status=_models.CustomFormModelStatus.READY, training_started_on=datetime.datetime(1, 1, 1), training_completed_on=datetime.datetime(1, 1, 1)
)
model_repr = "CustomFormModelInfo(model_id=1, status=ready, training_started_on=0001-01-01 00:00:00, training_completed_on=0001-01-01 00:00:00)"[:1024]
assert repr(model) == model_repr
Expand Down