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] enable logging for live tests #12110

Merged
merged 1 commit into from
Jun 18, 2020
Merged
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
22 changes: 22 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import pytest
import re
import logging
from azure.core.credentials import AzureKeyCredential, AccessToken
from devtools_testutils import (
AzureTestCase,
Expand All @@ -25,6 +26,8 @@
)
from azure_devtools.scenario_tests.utilities import is_text_payload

LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'
ENABLE_LOGGER = os.getenv('ENABLE_LOGGER', "False")
REGION = os.getenv('REGION', 'centraluseuap')


Expand Down Expand Up @@ -72,6 +75,7 @@ class FormRecognizerTest(AzureTestCase):
def __init__(self, method_name):
super(FormRecognizerTest, self).__init__(method_name)
self.recording_processors.append(AccessTokenReplacer())
self.configure_logging()

# URL samples
self.receipt_url_jpg = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-allinone.jpg"
Expand Down Expand Up @@ -109,6 +113,23 @@ def generate_oauth_token(self):
def generate_fake_token(self):
return FakeTokenCredential()

def configure_logging(self):
self.enable_logging() if ENABLE_LOGGER == "True" else self.disable_logging()

def enable_logging(self):
self.logger = logging.getLogger('azure')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
self.logger.handlers = [handler]
self.logger.setLevel(logging.DEBUG)
self.logger.propagate = True
self.logger.disabled = False

def disable_logging(self):
self.logger.propagate = False
self.logger.disabled = True
self.logger.handlers = []

def assertModelTransformCorrect(self, model, actual, unlabeled=False):
self.assertEqual(model.model_id, actual.model_info.model_id)
self.assertEqual(model.requested_on, actual.model_info.created_date_time)
Expand Down Expand Up @@ -543,6 +564,7 @@ def create_form_client(self, **kwargs):
form_recognizer_account,
AzureKeyCredential(form_recognizer_account_key),
polling_interval=polling_interval,
logging_enable=True if ENABLE_LOGGER == "True" else False,
**self.client_kwargs
)

Expand Down