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

changes in samples tests #12090

Merged
merged 2 commits into from
Jun 17, 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
21 changes: 11 additions & 10 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from azure.ai.formrecognizer import FormTrainingClient
from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer

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

def run(cmd, my_env):
os.environ['PYTHONUNBUFFERED'] = "1"
Expand All @@ -45,21 +43,24 @@ def _test_file(file_name, account, key, root_dir='./samples'):
my_env = dict(os.environ)
if sys.version_info < (3, 5):
my_env = {key: str(val) for key, val in my_env.items()}
code, _, err = run([sys.executable, root_dir + '/' + file_name], my_env=my_env)
assert code == 0
assert err is None
code, out, err = run([sys.executable, root_dir + '/' + file_name], my_env=my_env)
try:
assert code == 0
assert err is None
except AssertionError as e:
e.args += (out, )
raise AssertionError(e)

class TestSamples(FormRecognizerTest):
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_authentication(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('AZURE_FORM_RECOGNIZER_AAD_ENDPOINT', 'AZURE_FORM_RECOGNIZER_AAD_ENDPOINT')
_test_file('sample_authentication.py', form_recognizer_account, form_recognizer_account_key)

@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_get_bounding_boxes(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
container_sas_url = os.environ['CONTAINER_SAS_URL']
poller = ftc.begin_training(container_sas_url, use_training_labels=False)
Expand All @@ -80,7 +81,7 @@ def test_sample_recognize_content(self, resource_group, location, form_recognize
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_recognize_custom_forms(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
container_sas_url = os.environ['CONTAINER_SAS_URL']
poller = ftc.begin_training(container_sas_url, use_training_labels=False)
Expand All @@ -101,11 +102,11 @@ def test_sample_recognize_receipts(self, resource_group, location, form_recogniz
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_train_model_with_labels(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
_test_file('sample_train_model_with_labels.py', form_recognizer_account, form_recognizer_account_key)

@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_train_model_without_labels(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
_test_file('sample_train_model_without_labels.py', form_recognizer_account, form_recognizer_account_key)
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
from azure.ai.formrecognizer.aio import FormTrainingClient
from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer

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

def run(cmd, my_env):
os.environ['PYTHONUNBUFFERED'] = "1"
proc = subprocess.Popen(cmd,
Expand All @@ -41,9 +38,13 @@ def run(cmd, my_env):
def _test_file(file_name, account, key, root_dir='./samples/async_samples'):
os.environ['AZURE_FORM_RECOGNIZER_ENDPOINT'] = account
os.environ['AZURE_FORM_RECOGNIZER_KEY'] = key
code, _, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ))
assert code == 0
assert err is None
code, out, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ))
try:
assert code == 0
assert err is None
except AssertionError as e:
e.args += (out, )
raise AssertionError(e)


class TestSamplesAsync(FormRecognizerTest):
Expand All @@ -56,7 +57,7 @@ def test_sample_authentication_async(self, resource_group, location, form_recogn
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
async def test_sample_get_bounding_boxes_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
container_sas_url = os.environ['CONTAINER_SAS_URL']
poller = await ftc.begin_training(container_sas_url, use_training_labels=False)
Expand All @@ -77,7 +78,7 @@ def test_sample_recognize_content_async(self, resource_group, location, form_rec
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
async def test_sample_recognize_custom_forms_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
container_sas_url = os.environ['CONTAINER_SAS_URL']
poller = await ftc.begin_training(container_sas_url, use_training_labels=False)
Expand All @@ -98,12 +99,12 @@ def test_sample_recognize_receipts_async(self, resource_group, location, form_re
@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_train_model_with_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
_test_file('sample_train_model_with_labels_async.py', form_recognizer_account, form_recognizer_account_key)

@pytest.mark.live_test_only
@GlobalFormRecognizerAccountPreparer()
def test_sample_train_model_without_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
_setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL')
os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL")
_test_file('sample_train_model_without_labels_async.py', form_recognizer_account, form_recognizer_account_key)