Skip to content

Commit

Permalink
enable logging for tests (#12110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Jun 18, 2020
1 parent b9639d1 commit 9dc54e9
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit 9dc54e9

Please sign in to comment.