Skip to content

Commit c05481c

Browse files
authored
changes in samples tests (#12090)
* changes in samples * oops
1 parent 02275b1 commit c05481c

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
from azure.ai.formrecognizer import FormTrainingClient
2626
from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer
2727

28-
def _setenv(key, val):
29-
os.environ[key] = os.getenv(val) or os.getenv(key)
3028

3129
def run(cmd, my_env):
3230
os.environ['PYTHONUNBUFFERED'] = "1"
@@ -45,21 +43,24 @@ def _test_file(file_name, account, key, root_dir='./samples'):
4543
my_env = dict(os.environ)
4644
if sys.version_info < (3, 5):
4745
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)
5153

5254
class TestSamples(FormRecognizerTest):
5355
@pytest.mark.live_test_only
5456
@GlobalFormRecognizerAccountPreparer()
5557
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')
5758
_test_file('sample_authentication.py', form_recognizer_account, form_recognizer_account_key)
5859

5960
@pytest.mark.live_test_only
6061
@GlobalFormRecognizerAccountPreparer()
6162
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")
6364
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
6465
container_sas_url = os.environ['CONTAINER_SAS_URL']
6566
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
8081
@pytest.mark.live_test_only
8182
@GlobalFormRecognizerAccountPreparer()
8283
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")
8485
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
8586
container_sas_url = os.environ['CONTAINER_SAS_URL']
8687
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
101102
@pytest.mark.live_test_only
102103
@GlobalFormRecognizerAccountPreparer()
103104
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")
105106
_test_file('sample_train_model_with_labels.py', form_recognizer_account, form_recognizer_account_key)
106107

107108
@pytest.mark.live_test_only
108109
@GlobalFormRecognizerAccountPreparer()
109110
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")
111112
_test_file('sample_train_model_without_labels.py', form_recognizer_account, form_recognizer_account_key)

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples_async.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
from azure.ai.formrecognizer.aio import FormTrainingClient
2525
from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer
2626

27-
def _setenv(key, val):
28-
os.environ[key] = os.getenv(val) or os.getenv(key)
29-
3027
def run(cmd, my_env):
3128
os.environ['PYTHONUNBUFFERED'] = "1"
3229
proc = subprocess.Popen(cmd,
@@ -41,9 +38,13 @@ def run(cmd, my_env):
4138
def _test_file(file_name, account, key, root_dir='./samples/async_samples'):
4239
os.environ['AZURE_FORM_RECOGNIZER_ENDPOINT'] = account
4340
os.environ['AZURE_FORM_RECOGNIZER_KEY'] = key
44-
code, _, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ))
45-
assert code == 0
46-
assert err is None
41+
code, out, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ))
42+
try:
43+
assert code == 0
44+
assert err is None
45+
except AssertionError as e:
46+
e.args += (out, )
47+
raise AssertionError(e)
4748

4849

4950
class TestSamplesAsync(FormRecognizerTest):
@@ -56,7 +57,7 @@ def test_sample_authentication_async(self, resource_group, location, form_recogn
5657
@pytest.mark.live_test_only
5758
@GlobalFormRecognizerAccountPreparer()
5859
async def test_sample_get_bounding_boxes_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
59-
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
60+
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
6061
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
6162
container_sas_url = os.environ['CONTAINER_SAS_URL']
6263
poller = await ftc.begin_training(container_sas_url, use_training_labels=False)
@@ -77,7 +78,7 @@ def test_sample_recognize_content_async(self, resource_group, location, form_rec
7778
@pytest.mark.live_test_only
7879
@GlobalFormRecognizerAccountPreparer()
7980
async def test_sample_recognize_custom_forms_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
80-
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
81+
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
8182
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
8283
container_sas_url = os.environ['CONTAINER_SAS_URL']
8384
poller = await ftc.begin_training(container_sas_url, use_training_labels=False)
@@ -98,12 +99,12 @@ def test_sample_recognize_receipts_async(self, resource_group, location, form_re
9899
@pytest.mark.live_test_only
99100
@GlobalFormRecognizerAccountPreparer()
100101
def test_sample_train_model_with_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
101-
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
102+
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
102103
_test_file('sample_train_model_with_labels_async.py', form_recognizer_account, form_recognizer_account_key)
103104

104105
@pytest.mark.live_test_only
105106
@GlobalFormRecognizerAccountPreparer()
106107
def test_sample_train_model_without_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
107-
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
108+
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
108109
_test_file('sample_train_model_without_labels_async.py', form_recognizer_account, form_recognizer_account_key)
109110

0 commit comments

Comments
 (0)