File: test_multiapi.py

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (87 lines) | stat: -rw-r--r-- 4,272 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

import functools
from testcase import FormRecognizerTest
from testcase import GlobalFormRecognizerAccountPreparer
from testcase import GlobalClientPreparer as _GlobalClientPreparer
from azure.ai.formrecognizer import FormRecognizerClient, FormTrainingClient, FormRecognizerApiVersion

FormRecognizerClientPreparer = functools.partial(_GlobalClientPreparer, FormRecognizerClient)
FormTrainingClientPreparer = functools.partial(_GlobalClientPreparer, FormTrainingClient)

class TestMultiapi(FormRecognizerTest):
    @GlobalFormRecognizerAccountPreparer()
    @FormRecognizerClientPreparer()
    def test_default_api_version_form_recognizer_client(self, client):
        assert "v2.1-preview.2" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormTrainingClientPreparer()
    def test_default_api_version_form_training_client(self, client):
        assert "v2.1-preview.2" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormRecognizerClientPreparer(client_kwargs={"api_version": FormRecognizerApiVersion.V2_0})
    def test_v2_0_form_recognizer_client(self, client):
        assert "v2.0" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormTrainingClientPreparer(client_kwargs={"api_version": FormRecognizerApiVersion.V2_0})
    def test_v2_0_form_training_client(self, client):
        assert "v2.0" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormRecognizerClientPreparer(client_kwargs={"api_version": FormRecognizerApiVersion.V2_1_PREVIEW})
    def test_v2_1_preview_1_form_recognizer_client(self, client):
        assert "v2.1-preview.2" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormTrainingClientPreparer(client_kwargs={"api_version": FormRecognizerApiVersion.V2_1_PREVIEW})
    def test_v2_1_preview_1_form_training_client(self, client):
        assert "v2.1-preview.2" in client._client._client._base_url

    @GlobalFormRecognizerAccountPreparer()
    @FormTrainingClientPreparer(training=True, client_kwargs={"api_version": FormRecognizerApiVersion.V2_0})
    def test_v2_0_compatibility(self, client, container_sas_url):
        # test that the addition of new attributes in v2.1 does not break v2.0

        label_poller = client.begin_training(container_sas_url, use_training_labels=True)
        label_result = label_poller.result()

        unlabel_poller = client.begin_training(container_sas_url, use_training_labels=False)
        unlabel_result = unlabel_poller.result()

        assert label_result.properties is None
        assert label_result.model_name is None
        assert unlabel_result.properties is None
        assert unlabel_result.properties is None
        assert label_result.training_documents[0].model_id is None
        assert unlabel_result.training_documents[0].model_id is None

        form_client = client.get_form_recognizer_client()
        label_poller = form_client.begin_recognize_custom_forms_from_url(label_result.model_id, self.form_url_jpg, include_field_elements=True)
        unlabel_poller = form_client.begin_recognize_custom_forms_from_url(unlabel_result.model_id, self.form_url_jpg, include_field_elements=True)


        label_form_result = label_poller.result()
        unlabel_form_result = unlabel_poller.result()

        assert unlabel_form_result[0].form_type_confidence is None
        assert label_form_result[0].form_type_confidence is None
        assert unlabel_form_result[0].pages[0].selection_marks is None
        assert label_form_result[0].pages[0].selection_marks is None
        assert unlabel_form_result[0].pages[0].tables[0].bounding_box is None
        assert label_form_result[0].pages[0].tables[0].bounding_box is None
        assert unlabel_form_result[0].pages[0].lines[0].appearance is None
        assert label_form_result[0].pages[0].lines[0].appearance is None

        models = client.list_custom_models()
        model = list(models)[0]

        assert model.model_name is None
        assert model.properties is None