Esempio n. 1
0
 def loadLocalConfiguration(self, loadLocalConfig, printRootPathStatus,
                            globalsEverything):
     self.loadLocalConfig = loadLocalConfig
     self.localConfiguration = {}
     if self.loadLocalConfig:
         try:
             self.localConfiguration = self.getSettingTree(
                 settingFilePath=Globals.LOCAL_CONFIGURATION_FILE_NAME,
                 settingTree=None)
         except Exception as exception:
             self.log(
                 f'Failed to load {Globals.LOCAL_CONFIGURATION_FILE_NAME} settings',
                 exception=exception)
         keyQuery = SettingHelper.querySetting(AttributeKey.KW_KEY,
                                               self.localConfiguration)
         keyValueQuery = {}
         for key, value in keyQuery.items():
             KW_DOT_KEY = f'{c.DOT}{AttributeKey.KW_KEY}'
             if key.endswith(KW_DOT_KEY):
                 environmentInjection = SettingHelper.getSetting(
                     key[:-len(KW_DOT_KEY)], self.localConfiguration)
                 if (ObjectHelper.isDictionary(environmentInjection)
                         and AttributeKey.KW_KEY in environmentInjection
                         and AttributeKey.KW_VALUE in environmentInjection
                         and 2 == len(environmentInjection)):
                     EnvironmentHelper.update(
                         environmentInjection[AttributeKey.KW_KEY],
                         environmentInjection[AttributeKey.KW_VALUE])
     log.loadSettings()
     self.printRootPathStatus = printRootPathStatus
     self.globalsEverything = globalsEverything
     self.ignoreModules = IGNORE_MODULES
     self.ignoreResources = IGNORE_REOURCES
     self.activeEnvironment = SettingHelper.getActiveEnvironment()
     if ObjectHelper.isNotEmpty(
             self.localConfiguration) and SettingHelper.getSetting(
                 'print-status', self.localConfiguration):
         SettingHelper.printSettings(self.localConfiguration,
                                     "Local Configuration")
         basicSettingsAsDictionary = {
             'activeEnvironment': self.activeEnvironment,
             'successStatus': self.successStatus,
             'settingStatus': self.settingStatus,
             'debugStatus': self.debugStatus,
             'warningStatus': self.warningStatus,
             'failureStatus': self.failureStatus,
             'errorStatus': self.errorStatus,
             'wrapperStatus': self.wrapperStatus,
             'infoStatus': self.infoStatus,
             'statusStatus': self.statusStatus,
             'logStatus': self.logStatus,
             'globalsEverything': self.globalsEverything,
             'printRootPathStatus': self.printRootPathStatus
         }
         log.prettyPython(self.__class__,
                          f'Basic settings',
                          basicSettingsAsDictionary,
                          logLevel=log.SETTING)
Esempio n. 2
0
def handleEnvironmentChangesProperly_withError():
    beforeTestEnvironmentSettings = {**EnvironmentHelper.getSet()}
    inBetweenTestEnvironmentSettings = None
    afterTestEnvironmentSettings = None
    someExceptionMessage = 'some exception message'

    # Arrange
    def myBeforeAction(c, d=None):
        return d + c

    def myAfterAction(c, d=None):
        return c + d

    def myFunction(a):
        raise Exception(someExceptionMessage)

    returns = {}

    @Test(callBefore=myBeforeAction,
          argsOfCallBefore='f',
          kwargsOfCallBefore={'d': 'g'},
          callAfter=myAfterAction,
          argsOfCallAfter='h',
          kwargsOfCallAfter={'d': 'i'},
          returns=returns,
          environmentVariables={
              SettingHelper.ACTIVE_ENVIRONMENT: None,
              **MUTED_LOG_HELPER_SETTINGS
          })
    def myTest():
        inBetweenTestEnvironmentSettings = EnvironmentHelper.getSet()
        assert ObjectHelper.isNotNone(inBetweenTestEnvironmentSettings)
        assert ObjectHelper.isDictionary(inBetweenTestEnvironmentSettings)
        assert 'a' == myFunction('a')
        return inBetweenTestEnvironmentSettings

    # Act
    try:
        inBetweenTestEnvironmentSettings = myTest()
    except Exception as e:
        exception = e
    afterTestEnvironmentSettings = {**EnvironmentHelper.getSet()}

    # Assert
    assert 'gf' == returns['returnOfCallBefore']
    assert 'hi' == returns['returnOfCallAfter']
    assert ObjectHelper.isNotEmpty(exception)
    assert someExceptionMessage == str(exception)
    assert ObjectHelper.isNotNone(beforeTestEnvironmentSettings)
    assert ObjectHelper.isDictionary(beforeTestEnvironmentSettings)
    assert ObjectHelper.isNone(inBetweenTestEnvironmentSettings)
    assert ObjectHelper.isNotNone(afterTestEnvironmentSettings)
    assert ObjectHelper.isDictionary(afterTestEnvironmentSettings)
    assert afterTestEnvironmentSettings == beforeTestEnvironmentSettings
    assert not beforeTestEnvironmentSettings == inBetweenTestEnvironmentSettings
Esempio n. 3
0
 def makePathTreeVisible(self, path):
     node = {}
     nodeSons = EnvironmentHelper.listDirectoryContent(path)
     for nodeSon in nodeSons:
         if self.nodeIsValid(nodeSon):
             nodeSonPath = f'{path}{EnvironmentHelper.OS_SEPARATOR}{nodeSon}'
             try:
                 node[nodeSon] = self.makePathTreeVisible(nodeSonPath)
             except:
                 node[nodeSon] = c.NOTHING
     EnvironmentHelper.appendPath(path)
     return node
Esempio n. 4
0
def mustLogEnvironmentSettings():
    # Arrange

    # Act
    SettingHelper.logEnvironmentSettings()

    # Assert
    assert SettingHelper.LOCAL_ENVIRONMENT == EnvironmentHelper.get(
        SettingHelper.ACTIVE_ENVIRONMENT)
    assert SettingHelper.LOCAL_ENVIRONMENT == SettingHelper.getActiveEnvironment(
    )
    assert SettingHelper.activeEnvironmentIsLocal()
    assert "some value" == EnvironmentHelper.get('SOME_PARTICULAR_SETTING')
def osIdentifierTest() :
    # arrange

    # act
    isWindows = EnvironmentHelper.isWindows()
    isLinux = EnvironmentHelper.isLinux()

    # assert
    assert ObjectHelper.isNotNone(isWindows)
    assert ObjectHelper.isNotNone(isLinux)
    assert ObjectHelper.isNativeClassInstance(isWindows)
    assert ObjectHelper.isNativeClassInstance(isLinux)
    assert bool == type(isWindows)
    assert bool == type(isLinux)
    assert isLinux or isWindows 
Esempio n. 6
0
def handleEnvironmentChangesProperly_withSuccess_whenActionsHaveNoArguments():
    beforeTestEnvironmentSettings = {**EnvironmentHelper.getSet()}
    inBetweenTestEnvironmentSettings = None
    afterTestEnvironmentSettings = None
    MY_BEFORE_ACTION_RETURN = RandomHelper.string(minimum=10)
    MY_AFTER_ACTION_RETURN = RandomHelper.string(minimum=10)

    # Arrange
    def myBeforeAction():
        return MY_BEFORE_ACTION_RETURN

    def myAfterAction():
        return MY_AFTER_ACTION_RETURN

    def myFunction(a):
        return a

    returns = {}

    @Test(callBefore=myBeforeAction,
          callAfter=myAfterAction,
          returns=returns,
          environmentVariables={
              SettingHelper.ACTIVE_ENVIRONMENT: None,
              **MUTED_LOG_HELPER_SETTINGS
          })
    def myTest():
        inBetweenTestEnvironmentSettings = EnvironmentHelper.getSet()
        assert ObjectHelper.isNotNone(inBetweenTestEnvironmentSettings)
        assert ObjectHelper.isDictionary(inBetweenTestEnvironmentSettings)
        assert 'a' == myFunction('a')
        return inBetweenTestEnvironmentSettings

    # Act
    inBetweenTestEnvironmentSettings = myTest()
    afterTestEnvironmentSettings = {**EnvironmentHelper.getSet()}

    # Assert
    assert MY_BEFORE_ACTION_RETURN == returns['returnOfCallBefore']
    assert MY_AFTER_ACTION_RETURN == returns['returnOfCallAfter']
    assert ObjectHelper.isNotNone(beforeTestEnvironmentSettings)
    assert ObjectHelper.isDictionary(beforeTestEnvironmentSettings)
    assert ObjectHelper.isNotNone(inBetweenTestEnvironmentSettings)
    assert ObjectHelper.isDictionary(inBetweenTestEnvironmentSettings)
    assert ObjectHelper.isNotNone(afterTestEnvironmentSettings)
    assert ObjectHelper.isDictionary(afterTestEnvironmentSettings)
    assert afterTestEnvironmentSettings == beforeTestEnvironmentSettings
    assert not beforeTestEnvironmentSettings == inBetweenTestEnvironmentSettings
Esempio n. 7
0
def mustLogWithoutColors():
    # Arrange
    noExceptionThrown = 'exception not thrown'
    someLogMessage = 'some log message'
    someExceptionMessage = 'some exception message'
    someInnerExceptionMessage = 'some inner exception message'
    exception = None
    someExceptionMessageWithStackTrace = f'{someExceptionMessage} with stacktrace'
    someExceptionMessageWithoutStackTrace = f'{someExceptionMessage} without stacktrace'

    def controlableException(logType, muteStackTrace=False):
        try:
            raise Exception(
                someExceptionMessageWithoutStackTrace
                if muteStackTrace else someExceptionMessageWithStackTrace)
        except Exception as exception:
            if logType in OPTIONAL_EXCEPTION_LOG_TYPES:
                logType(logType,
                        someLogMessage,
                        exception=exception,
                        muteStackTrace=muteStackTrace)
            else:
                logType(logType,
                        someLogMessage,
                        exception,
                        muteStackTrace=muteStackTrace)

    # Act
    log.success(log.success, someLogMessage)
    log.setting(log.setting, someLogMessage)
    log.debug(log.debug, someLogMessage)
    log.warning(log.warning, someLogMessage)

    controlableException(log.log)
    controlableException(log.debug)
    controlableException(log.warning)
    controlableException(log.wraper)
    controlableException(log.failure)
    controlableException(log.error)
    controlableException(log.test)

    controlableException(log.log, muteStackTrace=True)
    controlableException(log.debug, muteStackTrace=True)
    controlableException(log.warning, muteStackTrace=True)
    controlableException(log.wraper, muteStackTrace=True)
    controlableException(log.failure, muteStackTrace=True)
    controlableException(log.error, muteStackTrace=True)
    controlableException(log.test, muteStackTrace=True)

    log.log(log.log, someLogMessage, None)
    log.debug(log.debug, someLogMessage, None)
    log.warning(log.warning, someLogMessage, None)
    log.wraper(log.wraper, noExceptionThrown, None)
    log.failure(log.failure, noExceptionThrown, None)
    log.error(log.error, noExceptionThrown, None)
    log.test(log.test, someLogMessage, None)

    # Assert
    assert 'my environment' == EnvironmentHelper.get(
        SettingHelper.ACTIVE_ENVIRONMENT)
def overrideDocumentation(apiInstance):
    try :
        documentationAsString = StringHelper.prettyJson(apiInstance.documentation)
        documentationFolderPath = getDocumentationFolderPath(apiInstance)
        documentationFilePath = getDocumentationFilePath(apiInstance)
        try:
            if not EnvironmentHelper.isDirectory(documentationFolderPath) :
                accessRights = 0o777 # define the access rights. write and read
                EnvironmentHelper.makeDirectory(documentationFolderPath, accessRights)
        except OSError as exception:
            exceptionMessage = f'Creation of the directory {documentationFilePath} failed'
            log.log(overrideDocumentation, exceptionMessage, exception=exception)
            raise Exception(exceptionMessage)
        with open(getDocumentationFilePath(apiInstance), c.OVERRIDE, encoding=c.ENCODING) as documentationFile :
            documentationFile.write(documentationAsString)
    except Exception as exception :
        log.log(overrideDocumentation,"Error while overriding OpenApi documentation file",exception)
        raise exception
Esempio n. 9
0
 def getPathTreeFromPath(self, path):
     node = {}
     nodeSons = EnvironmentHelper.listDirectoryContent(path)
     for nodeSon in nodeSons:
         if self.nodeIsValid(nodeSon):
             nodeSonPath = f'{path}{EnvironmentHelper.OS_SEPARATOR}{nodeSon}'
             try:
                 node[nodeSon] = self.getPathTreeFromPath(nodeSonPath)
             except:
                 pass
     return node
Esempio n. 10
0
 def addNode(self, nodePath):
     node = {}
     try:
         nodeSons = EnvironmentHelper.listDirectoryContent(nodePath)
         for nodeSon in nodeSons:
             nodeSonPath = f'{nodePath}{EnvironmentHelper.OS_SEPARATOR}{nodeSon}'
             try:
                 node[nodeSon] = self.addNode(nodeSonPath)
             except:
                 node[nodeSon] = c.NOTHING
     except Exception as exception:
         self.failure(f'Not possible to run addNode({nodePath}) rotine',
                      exception,
                      muteStackTrace=True)
     return node
Esempio n. 11
0
 def giveLocalVisibilityToFrameworkApis(self, apiPackageNameList):
     if apiPackageNameList:
         localPackageNameList = EnvironmentHelper.listDirectoryContent(
             self.apisPath)
         for packageName in localPackageNameList:
             if packageName not in self.apiTree.keys(
             ) and packageName in apiPackageNameList:
                 packagePath = f'{self.apisPath}{packageName}'
                 try:
                     self.apiTree[packageName] = self.makePathTreeVisible(
                         packagePath)
                 except:
                     self.apiTree[packageName] = c.NOTHING
         if self.printStatus:
             self.printTree(self.apiTree, f'{c.DEBUG}Api tree')
Esempio n. 12
0
 def spotRootPath(self, rootPath):
     if self.printRootPathStatus:
         try:
             apiPackageList = EnvironmentHelper.listDirectoryContent(
                 rootPath)
             for apiPackage in apiPackageList:
                 self.rootPathTree[apiPackage] = self.addNode(
                     f'{rootPath}{apiPackage}')
             if self.printStatus:
                 self.printTree(
                     self.rootPathTree,
                     f'{c.DEBUG}Root tree (printRootPathStatus is active)')
         except Exception as exception:
             self.failure(
                 f'Not possible to run spotRootPath({rootPath}) rotine',
                 exception)
Esempio n. 13
0
 def makeApisAvaliable(self, apisPath):
     if self.globalsEverything:
         try:
             apiPackageList = EnvironmentHelper.listDirectoryContent(
                 apisPath)
             for apiPackage in apiPackageList:
                 if not apiPackage in list(self.apiTree.keys()):
                     self.apiTree[apiPackage] = self.makePathTreeVisible(
                         f'{apisPath}{apiPackage}')
             if self.printStatus:
                 self.printTree(
                     self.apiTree,
                     f'{c.DEBUG}Api tree (globalsEverithing is active)')
         except Exception as exception:
             self.error(
                 f'Not possible to run makeApisAvaliable({apisPath}) rotine',
                 exception)
Esempio n. 14
0
def shouldHandleMissingEnvironmentSettings():
    # Arrange
    exception = None
    globalsInstance = None

    # Act
    try:
        globalsInstance = globals.newGlobalsInstance(__file__,
                                                     loadLocalConfig=False)
    except Exception as ext:
        exception = ext

    # Assert
    assert ObjectHelper.isNotNone(globalsInstance)
    assert ObjectHelper.isNone(exception)
    assert 'missing_setting_file' == EnvironmentHelper.get(
        SettingHelper.ACTIVE_ENVIRONMENT)
    assert 'missing_setting_file' == SettingHelper.getActiveEnvironment()
Esempio n. 15
0
def newApp(filePath,
           successStatus=True,
           errorStatus=True,
           failureStatus=True,
           warningStatus=True,
           settingStatus=True,
           statusStatus=True,
           infoStatus=True,
           debugStatus=False,
           wrapperStatus=False,
           testStatus=False,
           logStatus=False):
    globalsInstance = globals.newGlobalsInstance(filePath,
                                                 successStatus=successStatus,
                                                 errorStatus=errorStatus,
                                                 failureStatus=failureStatus,
                                                 settingStatus=settingStatus,
                                                 statusStatus=statusStatus,
                                                 infoStatus=infoStatus,
                                                 debugStatus=debugStatus,
                                                 warningStatus=warningStatus,
                                                 wrapperStatus=wrapperStatus,
                                                 testStatus=testStatus,
                                                 logStatus=logStatus)
    try:
        app = globals.importResource(
            KW_APP,
            resourceModuleName=ConverterStatic.getValueOrDefault(
                globalsInstance.apiName,
                StringHelper.join(EnvironmentHelper.listDirectoryContent(
                    f'{globalsInstance.BASE_API_PATH}')[0].split(c.DOT)[:-1],
                                  character=c.DOT)),
            required=True)
    except Exception as exception:
        apiPath = f'{c.DOT}{EnvironmentHelper.OS_SEPARATOR}{globalsInstance.BASE_API_PATH}{globalsInstance.apiName}.py'
        errorMessage = f"Not possible to load app. Make shure it's name is properlly configured at '{globalsInstance.settingFilePath}' and it's instance is named 'app' at '{apiPath}'"
        log.error(newApp, errorMessage, exception)
        raise exception
    if ObjectHelper.isNone(app):
        app = globals.importResource(
            KW_APP, resourceModuleName=globalsInstance.apiName)
        raise Exception(
            'Not possible to load app. Check logs for more details')
    return app
Esempio n. 16
0
class GoogleCredentialsEnumeration:
    CUSTOM_SEARCH_API_KEY = EnumItem(
        credential=EnvironmentHelper.get('GOOGLE_CUSTOM_SEARCH_API_KEY'))
    CUSTOM_SEARCH_CSE_ID = EnumItem(
        credential=EnvironmentHelper.get('GOOGLE_CUSTOM_SEARCH_CSE_ID'))
Esempio n. 17
0
 def getUrl(self, dialect):
     log.log(self.getUrl, 'Loading repository configuration')
     url = EnvironmentHelper.get(self.ENV_DATABASE_URL)
     if isNeitherNoneNorBlank(url):
         dialect = None
         driver = None
         database = None
         username = None
         password = None
         host = None
         port = None
         schema = None
         log.log(
             self.getUrl,
             f'Prioritising repository url in {self.ENV_DATABASE_URL} environment variable'
         )
     else:
         url = self.globals.getSetting(
             f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_URL}'
         )
         if isNeitherNoneNorBlank(url):
             dialect = None
             driver = None
             database = None
             username = None
             password = None
             host = None
             port = None
             schema = None
             log.log(self.getUrl,
                     f'Prioritising repository url in yamel configuration')
         else:
             url = c.NOTHING
             driver = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_DRIVER}'
             )
             database = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_DATABASE}'
             )
             username = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_USERNAME}'
             )
             password = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_PASSWORD}'
             )
             host = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_HOST}'
             )
             port = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_PORT}'
             )
             schema = self.globals.getSetting(
                 f'{self.KW_API}{c.DOT}{self.KW_DATABASE}{c.DOT}{self.KW_REPOSITORY_SCHEMA}'
             )
             if isNeitherNoneNorBlank(username) and isNeitherNoneNorBlank(
                     password):
                 url += f'{username}{c.COLON}{password}'
             if isNeitherNoneNorBlank(host) and isNeitherNoneNorBlank(port):
                 url += f'{c.ARROBA}{host}{c.COLON}{port}'
             url += c.SLASH
             database = f'{database}' if isNeitherNoneNorBlank(
                 database
             ) else f'{self.DEFAULT_LOCAL_STORAGE_NAME if ObjectHelper.isNone(self.globals.apiName) else self.globals.apiName}{c.DOT}{self.EXTENSION}'
             if not isNeitherNoneNorBlank(dialect):
                 dialect = self.DEFAULT_DIALECT
             plusDriverOrNothing = f'{c.PLUS}{driver}' if isNeitherNoneNorBlank(
                 driver) else c.NOTHING
             dialectAndDriver = f'''{dialect}{plusDriverOrNothing}'''
             url = f'{dialectAndDriver}{c.COLON}{c.DOUBLE_SLASH}{url}{database}'
             log.log(self.getUrl,
                     'Prioritising repository yamel configuration')
     if SettingHelper.activeEnvironmentIsLocal():
         log.prettyJson(
             self.getUrl,
             'Repository configuations', {
                 **self.globals.getSetting(f'{self.KW_API}{c.DOT}{self.KW_DATABASE}'),
                 **{
                     'dialect': dialect,
                     'driver': driver,
                     'database': database,
                     'username': username,
                     'password': password,
                     'host': host,
                     'port': port,
                     'schema': schema,
                     'url': url
                 }
             },
             logLevel=log.SETTING)
     # log.prettyPython(self.getUrl, 'url', url, logLevel=log.LOG)
     return url
Esempio n. 18
0
import importlib

importlib.invalidate_caches()
from python_helper import EnvironmentHelper, log, RandomHelper

EnvironmentHelper.update("URL_VARIANT",
                         RandomHelper.integer(minimum=0, maximum=10000))
log.debug(log.debug, f'variant: {EnvironmentHelper.get("URL_VARIANT")}')

from python_helper import TestHelper

TestHelper.run(__file__)
# TestHelper.run(
#     __file__,
#     runOnly = [
#         'TestApiTest.testing_Client'
#     ]
# )
# TestHelper.run(
#     __file__,
#     runOnly = [
#         'EnumAnnotationTest.enum_withSuccess',
#         'EnumAnnotationTest.otherEnum_withSuccess',
#         'EnumAnnotationTest.python_framework_status',
#         'EnumAnnotationTest.enumName',
#         'EnumAnnotationTest.enumName_badImplementation',
#         'EnumAnnotationTest.map_whenArgIsNone',
#         'EnumAnnotationTest.Enum_whenHaveMoreThanOneInnerValue',
#         'EnumAnnotationTest.Enum_dot_map',
#         'EnumAnnotationTest.Enum_str',
#         'EnumAnnotationTest.Enum_strInOutput'
Esempio n. 19
0
 def myTest():
     inBetweenTestEnvironmentSettings = EnvironmentHelper.getSet()
     assert ObjectHelper.isNotNone(inBetweenTestEnvironmentSettings)
     assert ObjectHelper.isDictionary(inBetweenTestEnvironmentSettings)
     assert 'a' == myFunction('a')
     return inBetweenTestEnvironmentSettings
Esempio n. 20
0
    def __init__(self,
                 filePath,
                 loadLocalConfig=True,
                 settingsFileName=APPLICATION,
                 logStatus=DEFAULT_LOG_STATUS,
                 infoStatus=DEFAULT_INFO_STATUS,
                 statusStatus=DEFAULT_STATUS_STATUS,
                 successStatus=DEFAULT_SUCCESS_STATUS,
                 settingStatus=DEFAULT_SETTING_STATUS,
                 debugStatus=DEFAULT_DEBUG_STATUS,
                 warningStatus=DEFAULT_WARNING_STATUS,
                 failureStatus=DEFAULT_FAILURE_STATUS,
                 wrapperStatus=DEFAULT_WRAPPER_STATUS,
                 errorStatus=DEFAULT_ERROR_STATUS,
                 testStatus=DEFAULT_TEST_STATUS,
                 logsWithColors=DEFAULT_LOGS_WITH_COLORS,
                 encoding=c.ENCODING,
                 printRootPathStatus=False,
                 globalsEverything=False):

        if globalsInstanceIsNone():

            self.logsWithColors = EnvironmentHelper.update(
                log.ENABLE_LOGS_WITH_COLORS,
                logsWithColors or log.colorsEnabled(),
                default=DEFAULT_LOGS_WITH_COLORS)

            self.logStatus = EnvironmentHelper.update(
                log.LOG, logStatus, default=DEFAULT_LOG_STATUS)
            self.infoStatus = EnvironmentHelper.update(
                log.INFO, infoStatus, default=DEFAULT_INFO_STATUS)
            self.statusStatus = EnvironmentHelper.update(
                log.STATUS, statusStatus, default=DEFAULT_STATUS_STATUS)
            self.successStatus = EnvironmentHelper.update(
                log.SUCCESS, successStatus, default=DEFAULT_SUCCESS_STATUS)
            self.settingStatus = EnvironmentHelper.update(
                log.SETTING, settingStatus, default=DEFAULT_SETTING_STATUS)
            self.debugStatus = EnvironmentHelper.update(
                log.DEBUG, debugStatus, default=DEFAULT_DEBUG_STATUS)
            self.warningStatus = EnvironmentHelper.update(
                log.WARNING, warningStatus, default=DEFAULT_WARNING_STATUS)
            self.failureStatus = EnvironmentHelper.update(
                log.FAILURE, failureStatus, default=DEFAULT_FAILURE_STATUS)
            self.wrapperStatus = EnvironmentHelper.update(
                log.WRAPPER, wrapperStatus, default=DEFAULT_WRAPPER_STATUS)
            self.errorStatus = EnvironmentHelper.update(
                log.ERROR, errorStatus, default=DEFAULT_ERROR_STATUS)
            self.testStatus = EnvironmentHelper.update(
                log.TEST, testStatus, default=DEFAULT_TEST_STATUS)
            log.loadSettings()

            self.filePath = filePath
            self.characterFilterList = Globals.CHARACTER_FILTER
            self.nodeIgnoreList = Globals.NODE_IGNORE_LIST
            self.encoding = encoding

            self.loadLocalConfiguration(loadLocalConfig, printRootPathStatus,
                                        globalsEverything)

            self.setting(
                f'{self.__class__.__name__}{c.DOT}filePath: {self.filePath}')
            self.setting(f'__file__: {__file__}')

            self.buildApplicationPath()
            self.loadSettings(settingsFileName)
            self.update()
Esempio n. 21
0
def mustPrintMessageLog_withColors():
    # Arrange
    mustLogWithNewLine = 'must log with new line'
    mustNotLogWithNewLine = 'must not log with new line'
    mustLogWithoutNewLine = 'must log without new line'
    mustNotLogWithoutNewLine = 'must not log without new line'
    mustLogWithNewLineWithException = 'must log with new line with exception'
    mustNotLogWithNewLineWithException = 'must not log with new line with exception'
    mustLogWithoutNewLineWithException = 'must log without new line with exception'
    mustNotLogWithoutNewLineWithException = 'must not log without new line with exception'
    someExceptionMessage = 'some exception message'
    thrownException = None
    try:
        raise Exception(someExceptionMessage)
    except Exception as exception:
        thrownException = exception

    # Act
    log.printLog(mustLogWithNewLine, condition=True, newLine=True)
    log.printSuccess(mustLogWithNewLine, condition=True, newLine=True)
    log.printSetting(mustLogWithNewLine, condition=True, newLine=True)
    log.printDebug(mustLogWithNewLine,
                   condition=True,
                   newLine=True,
                   exception=None)
    log.printWarning(mustLogWithNewLine,
                     condition=True,
                     newLine=True,
                     exception=None)
    log.printWarper(mustLogWithNewLine,
                    condition=True,
                    newLine=True,
                    exception=None)
    log.printFailure(mustLogWithNewLine,
                     condition=True,
                     newLine=True,
                     exception=None)
    log.printError(mustLogWithNewLine,
                   condition=True,
                   newLine=True,
                   exception=None)
    log.printTest(mustLogWithNewLine,
                  condition=True,
                  newLine=True,
                  exception=None)

    log.printLog(mustNotLogWithNewLine, condition=False, newLine=True)
    log.printSuccess(mustNotLogWithNewLine, condition=False, newLine=True)
    log.printSetting(mustNotLogWithNewLine, condition=False, newLine=True)
    log.printDebug(mustNotLogWithNewLine,
                   condition=False,
                   newLine=True,
                   exception=None)
    log.printWarning(mustNotLogWithNewLine,
                     condition=False,
                     newLine=True,
                     exception=None)
    log.printWarper(mustNotLogWithNewLine,
                    condition=False,
                    newLine=True,
                    exception=None)
    log.printFailure(mustNotLogWithNewLine,
                     condition=False,
                     newLine=True,
                     exception=None)
    log.printError(mustNotLogWithNewLine,
                   condition=False,
                   newLine=True,
                   exception=None)
    log.printTest(mustNotLogWithNewLine,
                  condition=False,
                  newLine=True,
                  exception=None)

    log.printLog(mustLogWithoutNewLine, condition=True, newLine=False)
    log.printSuccess(mustLogWithoutNewLine, condition=True, newLine=False)
    log.printSetting(mustLogWithoutNewLine, condition=True, newLine=False)
    log.printDebug(mustLogWithoutNewLine,
                   condition=True,
                   newLine=False,
                   exception=None)
    log.printWarning(mustLogWithoutNewLine,
                     condition=True,
                     newLine=False,
                     exception=None)
    log.printWarper(mustLogWithoutNewLine,
                    condition=True,
                    newLine=False,
                    exception=None)
    log.printFailure(mustLogWithoutNewLine,
                     condition=True,
                     newLine=False,
                     exception=None)
    log.printError(mustLogWithoutNewLine,
                   condition=True,
                   newLine=False,
                   exception=None)
    log.printTest(mustLogWithoutNewLine,
                  condition=True,
                  newLine=False,
                  exception=None)

    log.printLog(mustNotLogWithoutNewLine, condition=False, newLine=False)
    log.printSuccess(mustNotLogWithoutNewLine, condition=False, newLine=False)
    log.printSetting(mustNotLogWithoutNewLine, condition=False, newLine=False)
    log.printDebug(mustNotLogWithoutNewLine,
                   condition=False,
                   newLine=False,
                   exception=None)
    log.printWarning(mustNotLogWithoutNewLine,
                     condition=False,
                     newLine=False,
                     exception=None)
    log.printWarper(mustNotLogWithoutNewLine,
                    condition=False,
                    newLine=False,
                    exception=None)
    log.printFailure(mustNotLogWithoutNewLine,
                     condition=False,
                     newLine=False,
                     exception=None)
    log.printError(mustNotLogWithoutNewLine,
                   condition=False,
                   newLine=False,
                   exception=None)
    log.printTest(mustNotLogWithoutNewLine,
                  condition=False,
                  newLine=False,
                  exception=None)

    log.printLog(mustLogWithNewLineWithException,
                 condition=True,
                 newLine=True,
                 exception=thrownException)
    log.printDebug(mustLogWithNewLineWithException,
                   condition=True,
                   newLine=True,
                   exception=thrownException)
    log.printWarning(mustLogWithNewLineWithException,
                     condition=True,
                     newLine=True,
                     exception=thrownException)
    log.printWarper(mustLogWithNewLineWithException,
                    condition=True,
                    newLine=True,
                    exception=thrownException)
    log.printFailure(mustLogWithNewLineWithException,
                     condition=True,
                     newLine=True,
                     exception=thrownException)
    log.printError(mustLogWithNewLineWithException,
                   condition=True,
                   newLine=True,
                   exception=thrownException)
    log.printTest(mustLogWithNewLineWithException,
                  condition=True,
                  newLine=True,
                  exception=thrownException)

    log.printLog(mustLogWithoutNewLineWithException,
                 condition=True,
                 newLine=False,
                 exception=thrownException)
    log.printDebug(mustLogWithoutNewLineWithException,
                   condition=True,
                   newLine=False,
                   exception=thrownException)
    log.printWarning(mustLogWithoutNewLineWithException,
                     condition=True,
                     newLine=False,
                     exception=thrownException)
    log.printWarper(mustLogWithoutNewLineWithException,
                    condition=True,
                    newLine=False,
                    exception=thrownException)
    log.printFailure(mustLogWithoutNewLineWithException,
                     condition=True,
                     newLine=False,
                     exception=thrownException)
    log.printError(mustLogWithoutNewLineWithException,
                   condition=True,
                   newLine=False,
                   exception=thrownException)
    log.printTest(mustLogWithoutNewLineWithException,
                  condition=True,
                  newLine=False,
                  exception=thrownException)

    log.printLog(mustNotLogWithNewLineWithException,
                 condition=False,
                 newLine=True,
                 exception=thrownException)
    log.printDebug(mustNotLogWithNewLineWithException,
                   condition=False,
                   newLine=True,
                   exception=thrownException)
    log.printWarning(mustNotLogWithNewLineWithException,
                     condition=False,
                     newLine=True,
                     exception=thrownException)
    log.printWarper(mustNotLogWithNewLineWithException,
                    condition=False,
                    newLine=True,
                    exception=thrownException)
    log.printFailure(mustNotLogWithNewLineWithException,
                     condition=False,
                     newLine=True,
                     exception=thrownException)
    log.printError(mustNotLogWithNewLineWithException,
                   condition=False,
                   newLine=True,
                   exception=thrownException)
    log.printTest(mustNotLogWithNewLineWithException,
                  condition=False,
                  newLine=True,
                  exception=thrownException)

    log.printLog(mustNotLogWithoutNewLineWithException,
                 condition=False,
                 newLine=False,
                 exception=thrownException)
    log.printDebug(mustNotLogWithoutNewLineWithException,
                   condition=False,
                   newLine=False,
                   exception=thrownException)
    log.printWarning(mustNotLogWithoutNewLineWithException,
                     condition=False,
                     newLine=False,
                     exception=thrownException)
    log.printWarper(mustNotLogWithoutNewLineWithException,
                    condition=False,
                    newLine=False,
                    exception=thrownException)
    log.printFailure(mustNotLogWithoutNewLineWithException,
                     condition=False,
                     newLine=False,
                     exception=thrownException)
    log.printError(mustNotLogWithoutNewLineWithException,
                   condition=False,
                   newLine=False,
                   exception=thrownException)
    log.printTest(mustNotLogWithoutNewLineWithException,
                  condition=False,
                  newLine=False,
                  exception=thrownException)

    # Assert
    assert True == SettingHelper.activeEnvironmentIsLocal()
    assert SettingHelper.LOCAL_ENVIRONMENT == EnvironmentHelper.get(
        SettingHelper.ACTIVE_ENVIRONMENT)
    assert SettingHelper.LOCAL_ENVIRONMENT == SettingHelper.getActiveEnvironment(
    )