25
25
from azure .ai .formrecognizer import FormTrainingClient
26
26
from testcase import FormRecognizerTest , GlobalFormRecognizerAccountPreparer
27
27
28
- def _setenv (key , val ):
29
- os .environ [key ] = os .getenv (val ) or os .getenv (key )
30
28
31
29
def run (cmd , my_env ):
32
30
os .environ ['PYTHONUNBUFFERED' ] = "1"
@@ -45,21 +43,24 @@ def _test_file(file_name, account, key, root_dir='./samples'):
45
43
my_env = dict (os .environ )
46
44
if sys .version_info < (3 , 5 ):
47
45
my_env = {key : str (val ) for key , val in my_env .items ()}
48
- code , _ , err = run ([sys .executable , root_dir + '/' + file_name ], my_env = my_env )
49
- assert code == 0
50
- assert err is None
46
+ code , out , err = run ([sys .executable , root_dir + '/' + file_name ], my_env = my_env )
47
+ try :
48
+ assert code == 0
49
+ assert err is None
50
+ except AssertionError as e :
51
+ e .args += (out , )
52
+ raise AssertionError (e )
51
53
52
54
class TestSamples (FormRecognizerTest ):
53
55
@pytest .mark .live_test_only
54
56
@GlobalFormRecognizerAccountPreparer ()
55
57
def test_sample_authentication (self , resource_group , location , form_recognizer_account , form_recognizer_account_key ):
56
- _setenv ('AZURE_FORM_RECOGNIZER_AAD_ENDPOINT' , 'AZURE_FORM_RECOGNIZER_AAD_ENDPOINT' )
57
58
_test_file ('sample_authentication.py' , form_recognizer_account , form_recognizer_account_key )
58
59
59
60
@pytest .mark .live_test_only
60
61
@GlobalFormRecognizerAccountPreparer ()
61
62
def test_sample_get_bounding_boxes (self , resource_group , location , form_recognizer_account , form_recognizer_account_key ):
62
- _setenv ( 'CONTAINER_SAS_URL' , 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL' )
63
+ os . environ [ 'CONTAINER_SAS_URL' ] = self . get_settings_value ( "FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL" )
63
64
ftc = FormTrainingClient (form_recognizer_account , AzureKeyCredential (form_recognizer_account_key ))
64
65
container_sas_url = os .environ ['CONTAINER_SAS_URL' ]
65
66
poller = ftc .begin_training (container_sas_url , use_training_labels = False )
@@ -80,7 +81,7 @@ def test_sample_recognize_content(self, resource_group, location, form_recognize
80
81
@pytest .mark .live_test_only
81
82
@GlobalFormRecognizerAccountPreparer ()
82
83
def test_sample_recognize_custom_forms (self , resource_group , location , form_recognizer_account , form_recognizer_account_key ):
83
- _setenv ( 'CONTAINER_SAS_URL' , 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL' )
84
+ os . environ [ 'CONTAINER_SAS_URL' ] = self . get_settings_value ( "FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL" )
84
85
ftc = FormTrainingClient (form_recognizer_account , AzureKeyCredential (form_recognizer_account_key ))
85
86
container_sas_url = os .environ ['CONTAINER_SAS_URL' ]
86
87
poller = ftc .begin_training (container_sas_url , use_training_labels = False )
@@ -101,11 +102,11 @@ def test_sample_recognize_receipts(self, resource_group, location, form_recogniz
101
102
@pytest .mark .live_test_only
102
103
@GlobalFormRecognizerAccountPreparer ()
103
104
def test_sample_train_model_with_labels (self , resource_group , location , form_recognizer_account , form_recognizer_account_key ):
104
- _setenv ( 'CONTAINER_SAS_URL' , 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL' )
105
+ os . environ [ 'CONTAINER_SAS_URL' ] = self . get_settings_value ( "FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL" )
105
106
_test_file ('sample_train_model_with_labels.py' , form_recognizer_account , form_recognizer_account_key )
106
107
107
108
@pytest .mark .live_test_only
108
109
@GlobalFormRecognizerAccountPreparer ()
109
110
def test_sample_train_model_without_labels (self , resource_group , location , form_recognizer_account , form_recognizer_account_key ):
110
- _setenv ( 'CONTAINER_SAS_URL' , 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL' )
111
+ os . environ [ 'CONTAINER_SAS_URL' ] = self . get_settings_value ( "FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL" )
111
112
_test_file ('sample_train_model_without_labels.py' , form_recognizer_account , form_recognizer_account_key )
0 commit comments