def getTestRuntimeInfo(times, testTime, totalTestTime):
    testRuntimeInfo = None
    try:
        testRuntimeInfo = f'It {StringHelper.getToBe(True, singular=1==times, tense=StringHelper.PAST)} {times} test run{StringHelper.getS(times > 1)} in {testTime} seconds. Total test time: {totalTestTime} seconds'
    except Exception as exception:
        LogHelper.warning(getTestRuntimeInfo,
                          'Not possible do get test runtime info',
                          exception=exception)
        testRuntimeInfo = c.NOTHING
    return testRuntimeInfo
def querySetting(keywordQuery, tree):
    if StringHelper.isBlank(keywordQuery) or ObjectHelper.isNotDictionary(
            tree):
        LogHelper.warning(
            querySetting,
            f'''Not possible to parse "{tree}". It's either is not a dictionary or "{keywordQuery}" keyword query is blank'''
        )
    querySet = {}
    SettingHelperHelper.keepSearching(keywordQuery, tree, querySet)
    return querySet
def setAttributeOrMethod(instance,
                         name,
                         attributeOrMethodInstance,
                         muteLogs=False):
    if ObjectHelper.isNotNone(instance) and ObjectHelper.isNotNone(name):
        try:
            setattr(instance, name, attributeOrMethodInstance)
        except Exception as exception:
            if not muteLogs:
                LogHelper.warning(
                    setAttributeOrMethod,
                    f'Not possible to set "{name}:{attributeOrMethodInstance}" to "{getClassName(instance, typeClass=c.TYPE_CLASS, muteLogs=muteLogs) if ObjectHelper.isNotNone(instance) else instance}" instance',
                    exception=exception)
def getAttributeOrMethod(instance, name, muteLogs=False, default=None):
    attributeOrMethodInstance = None
    if ObjectHelper.isNotNone(instance) and ObjectHelper.isNotNone(name):
        try:
            attributeOrMethodInstance = default if not hasattr(
                instance, name) else getattr(instance, name)
        except Exception as exception:
            if not muteLogs:
                LogHelper.warning(
                    getAttributeOrMethod,
                    f'Not possible to get "{name}" from "{getClassName(instance, typeClass=c.TYPE_CLASS, muteLogs=muteLogs) if ObjectHelper.isNotNone(instance) else instance}" instance',
                    exception=exception)
    return default if ObjectHelper.isNone(
        attributeOrMethodInstance) else attributeOrMethodInstance
def getModuleName(thing, typeModule=None, muteLogs=False):
    name = None
    try:
        if ObjectHelper.isEmpty(thing):
            name = getUndefindeName(typeModule)
        else:
            name = thing.__module__.split(c.DOT)[-1]
    except Exception as exception:
        name = getUndefindeName(typeModule)
        if not muteLogs:
            LogHelper.warning(
                None,
                f'Not possible to get module name of {thing}. Returning {name} insted',
                exception=exception)
    return name
def getName(thing, typeName=None, muteLogs=False):
    name = None
    try:
        if ObjectHelper.isEmpty(thing):
            name = getUndefindeName(typeName)
        else:
            name = thing.__name__
    except Exception as exception:
        name = getUndefindeName(typeName)
        if not muteLogs:
            LogHelper.warning(
                None,
                f'Not possible to get name of {thing}. Returning {name} insted',
                exception=exception)
    return name
def getClass(thing, typeClass=None, muteLogs=False):
    thingClass = None
    try:
        if ObjectHelper.isEmpty(thing):
            thingClass = typeClass
        else:
            thingClass = thing.__class__
    except Exception as exception:
        thingClass = type(None)
        if not muteLogs:
            LogHelper.warning(
                None,
                f'Not possible to get class of {thing}. Returning {thingClass} insted',
                exception=exception)
    return thingClass
def getClassName(thing, typeClass=None, muteLogs=False):
    name = None
    try:
        if ObjectHelper.isEmpty(thing):
            name = getUndefindeName(typeClass)
        else:
            name = getName(getClass(thing, muteLogs=muteLogs),
                           muteLogs=muteLogs)
    except Exception as exception:
        name = getUndefindeName(typeClass)
        if not muteLogs:
            LogHelper.warning(
                None,
                f'Not possible to get class name of {thing}. Returning {name} insted',
                exception=exception)
    return name
Exemple #9
0
def update(environmentKey, environmentValue, default=None) :
    if ObjectHelper.isNotEmpty(environmentKey) :
        associatedValue = None
        if not environmentValue is None :
            associatedValue = str(StringHelper.filterString(environmentValue))
            OS.environ[environmentKey] = associatedValue
        elif not default is None :
            associatedValue = str(StringHelper.filterString(default))
            OS.environ[environmentKey] = associatedValue
        else :
            try:
                delete(environmentKey)
            except Exception as exception :
                LogHelper.warning(update, f'Failed to delete "{environmentKey}" enviroment variable key', exception=exception)
        return associatedValue
    else :
        LogHelper.debug(update, f'arguments: environmentKey: {environmentKey}, environmentValue: {environmentValue}, default: {default}')
        raise Exception(f'Error associating environment variable "{environmentKey}" key to environment variable "{environmentValue}" value')