def containsValidSettingInjection(settingValue):
    if ObjectHelper.isNotNone(settingValue) and StringHelper.isNotBlank(
            settingValue) and 0 < settingValue.count(
                OPEN_SETTING_INJECTION) and settingValue.count(
                    c.OPEN_DICTIONARY) == settingValue.count(
                        c.CLOSE_DICTIONARY):
        splitedSettingValue = settingValue.split(OPEN_SETTING_INJECTION)
        settingValueList = []
        completeSettingValue = c.NOTHING
        for segment in splitedSettingValue if settingValue.startswith(
                OPEN_SETTING_INJECTION) else splitedSettingValue[1:]:
            if ObjectHelper.isNotNone(segment):
                if ObjectHelper.isNotNone(segment.count(
                        c.OPEN_DICTIONARY)) and not segment.count(
                            c.OPEN_DICTIONARY) == segment.count(
                                c.CLOSE_DICTIONARY) and 0 < segment.count(
                                    c.OPEN_DICTIONARY):
                    completeSettingValue += segment
                else:
                    splitedSegment = segment.split(CLOSE_SETTING_INJECTION)
                    completeSettingValue += splitedSegment[0]
                    settingValueList.append(
                        f'{OPEN_SETTING_INJECTION}{completeSettingValue}{CLOSE_SETTING_INJECTION}'
                    )
                    completeSettingValue = c.NOTHING
        return len(splitedSettingValue) == len(
            settingValueList) if settingValue.startswith(
                OPEN_SETTING_INJECTION) else len(
                    splitedSettingValue) == len(settingValueList) + 1
    elif ObjectHelper.isList(settingValue):
        return containsValidSettingInjection(str(settingValue))
    return False
def overrideSignatures(toOverride,
                       original,
                       forceName=None,
                       forceModuleName=None):
    try:
        if ObjectHelper.isNotNone(original):
            toOverride.__name__ = original.__name__ if ObjectHelper.isNone(
                forceName) else set(forceName)
            toOverride.__qualname__ = original.__qualname__ if ObjectHelper.isNone(
                forceName) else set(forceName)
            toOverride.__module__ = original.__module__ if ObjectHelper.isNone(
                forceName) else set(c.NOTHING)
        else:
            toOverride.__name__ = forceName if ObjectHelper.isNotNone(
                forceName) else set(toOverride.__name__)
            toOverride.__qualname__ = forceName if ObjectHelper.isNotNone(
                forceName) else set(toOverride.__qualname__)
            toOverride.__module__ = forceModuleName if ObjectHelper.isNotNone(
                forceModuleName) else set(toOverride.__module__)
    except Exception as exception:
        LogHelper.error(
            overrideSignatures,
            f'''Not possible to override signatures of {toOverride} by signatures of {original} method''',
            exception)
        raise exception
def getSettingInjectionListFromSettingValue(settingValue):
    if ObjectHelper.isList(settingValue):
        allElements = []
        for element in settingValue:
            elements = getSettingInjectionListFromSettingValue(element)
            if ObjectHelper.isList(elements):
                allElements += elements
        return allElements
    elif ObjectHelper.isNotNone(settingValue) and StringHelper.isNotBlank(
            settingValue):
        splitedSettingValue = settingValue.split(OPEN_SETTING_INJECTION)
        settingValueList = []
        completeSettingValue = c.NOTHING
        for segment in splitedSettingValue if settingValue.startswith(
                OPEN_SETTING_INJECTION) else splitedSettingValue[1:]:
            if ObjectHelper.isNotNone(segment) and StringHelper.isNotBlank(
                    segment):
                if ObjectHelper.isNotNone(segment.count(
                        c.OPEN_DICTIONARY)) and not segment.count(
                            c.OPEN_DICTIONARY) == segment.count(
                                c.CLOSE_DICTIONARY) and 0 < segment.count(
                                    c.OPEN_DICTIONARY):
                    completeSettingValue += segment
                else:
                    splitedSegment = segment.split(CLOSE_SETTING_INJECTION)
                    completeSettingValue += splitedSegment[0]
                    if ObjectHelper.isNotNone(
                            completeSettingValue) and StringHelper.isNotBlank(
                                completeSettingValue):
                        settingValueList.append(
                            f'{OPEN_SETTING_INJECTION}{completeSettingValue}{CLOSE_SETTING_INJECTION}'
                        )
                    completeSettingValue = c.NOTHING
        return settingValueList
    return []
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
示例#6
0
def softLog(origin,
            message,
            level,
            exception=None,
            muteStackTrace=False,
            newLine=False):
    if ObjectHelper.isNotNone(exception):
        hardLog(origin,
                message,
                exception,
                level,
                muteStackTrace=muteStackTrace)
    elif c.TRUE == getStatus(level):
        firstLayerColor, secondLayerColor, tirdLayerColor, resetColor = getColors(
            level)
        LogHelper.logIt(
            StringHelper.join([
                firstLayerColor, LEVEL_DICTIONARY[level][LOG_TEXT],
                *getOriginPortion(origin, tirdLayerColor, resetColor),
                secondLayerColor, message, resetColor,
                getNewLine(newLine,
                           exception=exception,
                           muteStackTrace=muteStackTrace)
            ]))
    elif not c.FALSE == getStatus(level):
        levelStatusError(method, level)
def handleAfter(resourceInstanceMethod, actionClass, args, kwargs, returns, methodReturn, inspectGlobals, methodReturnException=None, logResult=True) :
    inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'did run')
    if ObjectHelper.isNone(methodReturnException) :
        LogHelper.printSuccess(f'{ReflectionHelper.getMethodModuleNameDotName(resourceInstanceMethod)} test succeed', condition=logResult, newLine=False, margin=False)
    else :
        LogHelper.printError(f'{ReflectionHelper.getMethodModuleNameDotName(resourceInstanceMethod)} test failed', condition=logResult, newLine=False, margin=False, exception=methodReturnException)
    actionHandlerException = handle(resourceInstanceMethod, actionClass, args, kwargs, returns, AFTER_THE_TEST, RETURN_VALUE_FROM_CALL_AFTER)
    LogHelper.test(resourceInstanceMethod, 'Test completed')
    if ObjectHelper.isNotNone(methodReturnException) or ObjectHelper.isNotNone(actionHandlerException) :
        if ObjectHelper.isNotNone(methodReturnException) and ObjectHelper.isNotNone(actionHandlerException) :
            raise Exception(f'{LogHelper.getExceptionMessage(methodReturnException)}. Followed by: {LogHelper.getExceptionMessage(actionHandlerException)}')
        elif ObjectHelper.isNotNone(methodReturnException) :
            raise methodReturnException
        raise actionHandlerException
    if not TEST_VALUE_NOT_SET == methodReturn :
        return methodReturn
示例#8
0
 def unitTest(testModule, testName, data, testReturns, logResult):
     discountTimeEnd = time.time()
     unitTestException = None
     if logResult:
         LogHelper.test(unitTest,
                        f'{testName}{c.DOT}{data[1]} test started')
     moduleTestStartTime = time.time()
     try:
         testReturns[data[1]] = data[0]()
         LogHelper.printSuccess(
             f'{data[0].__module__}{c.DOT}{data[0].__name__} succeed',
             condition=logResult,
             newLine=False,
             margin=False)
     except Exception as exception:
         LogHelper.printError(
             f'{data[0].__module__}{c.DOT}{data[0].__name__} failed',
             condition=True,
             newLine=False,
             margin=False,
             exception=exception)
         unitTestException = exception
     if logResult:
         LogHelper.test(
             unitTest,
             f'{testName}{c.DOT}{data[1]} test completed in {time.time() - moduleTestStartTime} seconds'
         )
     if ObjectHelper.isNotNone(unitTestException):
         raise unitTestException
     someDidRun = True
     return testName, data, testReturns, someDidRun, logResult, discountTimeEnd
def sampleCollection(collection, collectionClass, length=None) :
    if ObjectHelper.isNotNone(length) :
        if ObjectHelper.isList(collection) :
            return collectionClass(random.sample(collection, length))
        return collectionClass(random.sample(list(collection), length))
    if ObjectHelper.isList(collection) :
        return random.choice(collection)
    return random.choice(list(collection))
def getSet(value):
    roughtValueList = value[1:-1].split(c.COMA)
    valueSet = set()
    for value in roughtValueList:
        gottenValue = getValue(value)
        if ObjectHelper.isNotNone(gottenValue):
            valueSet.add(gottenValue)
    return valueSet
示例#11
0
def updateTestModuleNames(testModuleNames, queryResult, runOnly, ignore):
    if not c.NOTHING == queryResult:
        for key, value in queryResult.items():
            if c.NOTHING == value and key.endswith(TEST_DOT_PY):
                testModuleName = key[:-len(DOT_PY)]
                if ObjectHelper.isNone(runOnly) or ObjectHelper.isNotNone(
                        runOnly) and testModuleName in runOnly:
                    testModuleNames.append(testModuleName)
            else:
                updateTestModuleNames(testModuleNames, value, runOnly, ignore)
def updateSettingValue(settingKey,
                       settingValue,
                       nodeKey,
                       settingTree,
                       isSameDepth=False,
                       isSettingInjection=False):
    # print(f'settingKey: {settingKey}, settingValue: {settingValue}, nodeKey: {nodeKey}, settingTree: {settingTree}, isSameDepth: {isSameDepth}')
    if StringHelper.isNotBlank(settingKey) and ObjectHelper.isNotNone(
            settingKey):
        # print(f'accessTree({nodeKey},{settingTree})[{settingKey}]: {accessTree(nodeKey,settingTree)}[{settingKey}]')
        # print(f'type(accessTree(nodeKey,settingTree)): {type(accessTree(nodeKey,settingTree))}')

        accessTree(nodeKey,
                   settingTree)[settingKey] = getSettingValueOrNewNode(
                       nodeKey,
                       settingKey,
                       settingValue,
                       isSameDepth=isSameDepth,
                       isSettingInjection=isSettingInjection)
    elif StringHelper.isNotBlank(nodeKey) and ObjectHelper.isNotNone(nodeKey):
        splittedNodeKey = nodeKey.split(c.DOT)
        if 1 < len(splittedNodeKey):
            accessSettingKey = splittedNodeKey[-1]
            accessNodeKey = c.DOT.join(splittedNodeKey[:-1])
        else:
            accessSettingKey = splittedNodeKey[-1]
            accessNodeKey = None
        accessTree(accessNodeKey,
                   settingTree)[accessSettingKey] = getSettingValueOrNewNode(
                       nodeKey,
                       settingKey,
                       settingValue,
                       isSameDepth=isSameDepth,
                       isSettingInjection=isSettingInjection)
    else:
        errorMessage = 'Node key and setting key cannot be None at the same time'
        exception = Exception(errorMessage)
        LogHelper.error(
            updateSettingValue,
            f'Error parsing settingKey: "{settingKey}", settingValue: {settingValue}, nodeKey: {nodeKey}, settingTree: {StringHelper.prettyPython(settingTree)}',
            errorMessage)
        raise exception
 def innerResourceInstanceMethod(*innerArgs,**innerKwargs) :
     methodReturn = None
     wraperException = None
     originalEnvironmentVariables, originalActiveEnvironment = SettingHelper.replaceEnvironmentVariables(environmentVariables)
     try :
         methodReturn = resourceInstanceMethod(*innerArgs,**innerKwargs)
     except Exception as exception :
         wraperException = exception
     SettingHelper.recoverEnvironmentVariables(environmentVariables, originalEnvironmentVariables, originalActiveEnvironment)
     if ObjectHelper.isNotNone(wraperException) :
         raise wraperException
     return methodReturn
def safelyGetSettingInjectionValue(settingKey,
                                   settingValue,
                                   nodeKey,
                                   settingTree,
                                   fallbackSettingTree=None):
    exception = None
    newSettingValue = None
    try:
        newSettingValue = getSettingInjectionValue(settingKey, settingValue,
                                                   nodeKey, settingTree)
    except Exception as e:
        exception = e
        LogHelper.log(
            safelyGetSettingInjectionValue,
            f'Not possible to load "{settingKey}" setting key from setting tree. Now trying to load it from fallback setting tree',
            exception=exception)
    if ObjectHelper.isNone(newSettingValue) and ObjectHelper.isNotNone(
            fallbackSettingTree):
        return getSettingInjectionValue(settingKey, settingValue, nodeKey,
                                        fallbackSettingTree)
    if ObjectHelper.isNotNone(exception):
        raise exception
    return newSettingValue
示例#15
0
def getErrorPortion(exception, muteStackTrace, firstLayerColor,
                    secondLayerColor, tirdLayerColor, resetColor):
    if ObjectHelper.isEmpty(exception):
        return [c.NOTHING]
    exceptionMessage = LogHelper.getExceptionMessage(exception)
    traceBackMessage = LogHelper.getTracebackMessage(muteStackTrace)
    traceBackMessageSplited = traceBackMessage.split(exceptionMessage)
    return [
        c.NEW_LINE, tirdLayerColor, *[
            t if t is not traceBackMessageSplited[-1] else
            t if t[-1] is not c.NEW_LINE else t[:-1]
            for t in traceBackMessageSplited if ObjectHelper.isNotNone(t)
        ], secondLayerColor, exceptionMessage, resetColor
    ]
示例#16
0
def updateSettingTree(toUpdateSettingTree, gatheringSettingTree):
    if ObjectHelper.isNotEmpty(gatheringSettingTree):
        if ObjectHelper.isNone(toUpdateSettingTree) or StringHelper.isBlank(
                toUpdateSettingTree):
            toUpdateSettingTree = {}
        if ObjectHelper.isCollection(
                gatheringSettingTree) and ObjectHelper.isDictionary(
                    gatheringSettingTree):
            for key, value in gatheringSettingTree.items():
                if ObjectHelper.isNotEmpty(value) and ObjectHelper.isNotNone(
                        value):
                    if key not in toUpdateSettingTree or ObjectHelper.isEmpty(
                            toUpdateSettingTree[key]):
                        toUpdateSettingTree[key] = value
                    else:
                        updateSettingTree(toUpdateSettingTree[key],
                                          gatheringSettingTree[key])
                elif key not in toUpdateSettingTree:
                    toUpdateSettingTree[key] = value
def handleSettingInjectionList(settingInjectionList,
                               settingTree,
                               fallbackSettingTree=None):
    if ObjectHelper.isNotEmptyCollection(
            settingInjectionList) and ObjectHelper.isNotNone(settingTree):
        try:
            done, stuck = handleSettingInjectionListLoop(
                False,
                False,
                settingTree,
                settingInjectionList,
                fallbackSettingTree,
                getSettingInjectionValueIgnoringFallbackSettingTree,
                verifyer=verifyDefaultSettingInjectionListHandler)
        except Exception as exception:
            LogHelper.error(
                handleSettingInjectionList,
                'Not possible to load setting injections properly', exception)
            raise exception
def accessTree(nodeKey, tree):
    if ObjectHelper.isNotNone(tree):
        strippedNodeKey = nodeKey.strip()
        if ObjectHelper.isEmpty(nodeKey):
            returnTree = None
            try:
                returnTree = StringHelper.filterString(tree)
            except Exception as exception:
                LogHelper.failure(
                    accessTree,
                    f'Failed to get filtered string from {tree} tree. Returning it the way it is by default',
                    exception)
                returnTree = tree
            return returnTree
        elif isinstance(nodeKey, str):
            nodeKeyList = nodeKey.split(c.DOT)
            if len(nodeKeyList) == 1:
                nextNodeKey = c.NOTHING
            else:
                nextNodeKey = c.DOT.join(nodeKeyList[1:])
            return accessTree(nextNodeKey, tree.get(nodeKeyList[0]))
def handleSettingInjectionListLoop(done,
                                   stuck,
                                   settingTree,
                                   settingInjectionList,
                                   fallbackSettingTree,
                                   handler,
                                   verifyer=None):
    while not done and not stuck:
        stuck = True
        isSettingInjectionCount = 0
        containsSettingInjectionCount = 0
        for settingInjection in settingInjectionList.copy():
            done, stuck, isSettingInjectionCount, containsSettingInjectionCount = handleSettingInjectionListByCallingHandler(
                done, stuck, isSettingInjectionCount,
                containsSettingInjectionCount, settingInjection, settingTree,
                settingInjectionList, fallbackSettingTree, handler)
        if ObjectHelper.isNotNone(verifyer):
            verifyer(done, stuck, isSettingInjectionCount,
                     containsSettingInjectionCount, settingTree,
                     settingInjectionList, fallbackSettingTree)
    return done, stuck
示例#20
0
def runModuleTests(testName, runnableTddModule, times, runSpecificTests,
                   testsToRun, logResult, globalsInstance):
    import globals
    testModule = globals.importModule(testName)
    dataList = ReflectionHelper.getAttributeDataList(testModule)
    LogHelper.prettyPython(
        runnableTddModule,
        f'{ReflectionHelper.getName(testModule)} tests loaded',
        dataList,
        logLevel=LogHelper.TEST)
    allShouldRun, someShouldRun, allDidRun, someDidRun = getRunStatus(
        testModule, dataList, runSpecificTests, testsToRun)
    testReturns = {}
    testTime = 0
    totalTestTimeStart = time.time()
    if someShouldRun:
        defaultMessage = f'{testName}{StringHelper.getS(allShouldRun)}'
        methodReturnException = None
        LogHelper.test(runModuleTests, f'{defaultMessage} started')
        try:
            allDidRun, someDidRun, testTime, testReturns = runnableTddModule(
                testName, testModule, dataList, times, runSpecificTests,
                testsToRun, allShouldRun, someShouldRun, logResult)
            LogHelper.printSuccess(
                f'{defaultMessage} succeed. {getTestRuntimeInfo(times, testTime, time.time() - totalTestTimeStart)}',
                condition=logResult,
                newLine=True,
                margin=False)
        except Exception as exception:
            methodReturnException = exception
            LogHelper.printError(f'{defaultMessage} failed',
                                 condition=True,
                                 newLine=True,
                                 margin=False,
                                 exception=methodReturnException)
        exceptionRaised = ObjectHelper.isNotNone(methodReturnException)
        defaultMessage = f'{testName}{StringHelper.getS(not exceptionRaised and allDidRun)}'
        if exceptionRaised:
            raise methodReturnException
    return allDidRun, someDidRun, testTime, testReturns
 def innerResourceInstanceMethod(*innerArgs,**innerKwargs) :
     handlerException = None
     handlerReturn = None
     inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'will impartialy observe')
     try :
         methodReturnException = None
         methodReturn = TEST_VALUE_NOT_SET
         handleBefore(resourceInstanceMethod, callBefore, argsOfCallBefore, kwargsOfCallBefore, returns, inspectGlobals)
         originalEnvironmentVariables, originalActiveEnvironment = SettingHelper.replaceEnvironmentVariables(environmentVariables)
         inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'is about to run')
         try :
             methodReturn = resourceInstanceMethod(*innerArgs,**innerKwargs)
         except Exception as exception :
             methodReturnException = exception
         inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'just run')
         SettingHelper.recoverEnvironmentVariables(environmentVariables, originalEnvironmentVariables, originalActiveEnvironment)
         handlerReturn = handleAfter(resourceInstanceMethod, callAfter, argsOfCallAfter, kwargsOfCallAfter, returns, methodReturn, inspectGlobals, methodReturnException=methodReturnException, logResult=logResult)
     except Exception as exception :
         handlerException = exception
     inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'impartialy observed')
     if ObjectHelper.isNotNone(handlerException) :
         raise handlerException
     return handlerReturn
示例#22
0
def getSettingTree(settingFilePath,
                   settingTree=None,
                   fallbackSettingFilePath=None,
                   fallbackSettingTree=None,
                   lazyLoad=False,
                   keepDepthInLongString=False,
                   depthStep=c.TAB_UNITS,
                   encoding=c.ENCODING):
    settingInjectionList = []
    fallbackSettingInjectionList = []
    if ObjectHelper.isNotNone(fallbackSettingFilePath):
        innerFallbackSettingTree, fallbackSettingInjectionList = getSettingTree(
            fallbackSettingFilePath,
            lazyLoad=True,
            keepDepthInLongString=keepDepthInLongString,
            depthStep=depthStep,
            encoding=encoding)
    else:
        innerFallbackSettingTree = {}
    with open(settingFilePath, c.READ, encoding=encoding) as settingsFile:
        allSettingLines = settingsFile.readlines()
    longStringCapturing = False
    quoteType = None
    longStringList = None
    depth = 0
    nodeRefference = 0
    nodeKey = c.NOTHING
    if settingTree is None:
        settingTree = {}
    for line, settingLine in enumerate(allSettingLines):
        if SettingHelperHelper.lineAproved(settingLine):
            if longStringCapturing:
                # print('lineAproved')
                if not currentDepth:
                    currentDepth = 0
                longStringList.append(depthStep * c.SPACE +
                                      settingLine if keepDepthInLongString else
                                      settingLine[depth:])
                if quoteType in str(settingLine):
                    longStringList[-1] = c.NOTHING.join(
                        longStringList[-1].split(quoteType))[:-1] + quoteType
                    settingValue = c.NOTHING.join(longStringList)
                    nodeKey = SettingHelperHelper.updateSettingTreeAndReturnNodeKey(
                        settingKey, settingValue, nodeKey, settingTree, False)
                    longStringCapturing = False
                    quoteType = None
                    longStringList = None
            else:
                currentDepth = SettingHelperHelper.getDepth(settingLine)
                isSameDepth = SettingHelperHelper.nextValidLineIsAtTheSameDepthOrLess(
                    currentDepth, line, allSettingLines)
                # print(f'isSameDepth: {isSameDepth}')
                if currentDepth == depth:
                    # print('currentDepth == depth')
                    settingKey, settingValue, nodeKey, longStringCapturing, quoteType, longStringList = SettingHelperHelper.settingTreeInnerLoop(
                        settingLine, nodeKey, settingTree, longStringCapturing,
                        quoteType, longStringList, settingInjectionList,
                        lazyLoad, isSameDepth)
                elif currentDepth > depth:
                    # print('currentDepth > depth')
                    currentNodeRefference = currentDepth // (currentDepth -
                                                             depth)
                    if currentNodeRefference - nodeRefference == 1:
                        settingKey, settingValue, nodeKey, longStringCapturing, quoteType, longStringList = SettingHelperHelper.settingTreeInnerLoop(
                            settingLine, nodeKey, settingTree,
                            longStringCapturing, quoteType, longStringList,
                            settingInjectionList, lazyLoad, isSameDepth)
                        nodeRefference = currentNodeRefference
                        depth = currentDepth
                elif currentDepth < depth:
                    # print('currentDepth < depth')
                    nodeRefference = currentDepth // depthStep  ###- if line.split(':')[0] == currentDepth + c.TAB_UNITS * ' ' +
                    depth = currentDepth
                    # print()
                    # print()
                    # print()
                    # print(str(line))
                    # print(str(nodeKey))
                    # print(str(settingLine))
                    splitedNodeKey = nodeKey.split(c.DOT)[:nodeRefference]
                    splitedNodeKeyLength = len(splitedNodeKey)
                    if splitedNodeKeyLength == 0:
                        nodeKey = c.NOTHING
                    elif splitedNodeKeyLength == 1:
                        nodeKey = splitedNodeKey[0]
                    else:
                        nodeKey = c.DOT.join(splitedNodeKey)
                    settingKey, settingValue, nodeKey, longStringCapturing, quoteType, longStringList = SettingHelperHelper.settingTreeInnerLoop(
                        settingLine, nodeKey, settingTree, longStringCapturing,
                        quoteType, longStringList, settingInjectionList,
                        lazyLoad, isSameDepth)
                    # if ObjectHelper.isNotNone(settingValue) and ObjectHelper.isNotEmpty(settingValue) :
                    depth = currentDepth
    if lazyLoad:
        return settingTree, settingInjectionList
    elif (ObjectHelper.isNotEmptyCollection(innerFallbackSettingTree)
          and ObjectHelper.isNotNone(fallbackSettingFilePath)):
        for fallbackSettingInjection in fallbackSettingInjectionList.copy():
            for settingInjection in settingInjectionList.copy():
                if (fallbackSettingInjection[SettingHelperHelper.SETTING_KEY]
                        == settingInjection[SettingHelperHelper.SETTING_KEY]
                        and fallbackSettingInjection[
                            SettingHelperHelper.SETTING_NODE_KEY]
                        == settingInjection[
                            SettingHelperHelper.SETTING_NODE_KEY]):
                    fallbackSettingInjectionList.remove(
                        fallbackSettingInjection)
        settingInjectionList += fallbackSettingInjectionList
        updateSettingTree(settingTree, innerFallbackSettingTree)
        SettingHelperHelper.handleSettingInjectionList(
            settingInjectionList,
            settingTree,
            fallbackSettingTree=innerFallbackSettingTree)
    SettingHelperHelper.handleSettingInjectionList(
        settingInjectionList,
        settingTree,
        fallbackSettingTree=fallbackSettingTree)
    updateSettingTree(settingTree, fallbackSettingTree)
    return settingTree
示例#23
0
def minusDays(givenDay, days=None, deltaInDays=None):
    if ObjectHelper.isNotNone(minutes):
        deltaInDays = datetime.timedelta(days=days)
    return forcedlyGetDateTime(str(givenDay)) - deltaInDays
示例#24
0
def of(date=None, time=None, dateTime=None):
    if ObjectHelper.isNotNone(dateTime):
        date = dateTime.split()[0]
        time = dateTime.split()[1]
    return datetime.datetime.combine(forcedlyGetDate(date),
                                     forcedlyGetTime(time))
示例#25
0
def getWeekDay(ofDatetime=None, ofDate=None, ofTime=None):
    if ObjectHelper.isNotNone(ofDatetime):
        return forcedlyGetDateTime(ofDatetime).weekday()
    elif ObjectHelper.isNotNone(ofDate) and ObjectHelper.isNotNone(ofTime):
        return of(forcedlyGetDate(ofDate), forcedlyGetTime(ofTime)).weekday()
    return datetime.datetime.now().weekday()
def getColorValue(thing, color) :
    return color if ObjectHelper.isNotNone(color) else c.NATIVE_PROMPT_COLOR.get(
        ReflectionHelper.getName(type(thing)),
        c.DARK_BLUE
    )
def actionIsPresent(actionClass) :
    return not TEST_VALUE_NOT_SET == actionClass and ObjectHelper.isNotNone(actionClass)
示例#28
0
def getNewLine(newLine, exception=None, muteStackTrace=False):
    return c.NEW_LINE if (newLine and ObjectHelper.isNone(exception)) or (
        ObjectHelper.isNotNone(exception) and NO_TRACEBACK_PRESENT_MESSAGE
        == LogHelper.getTracebackMessage(muteStackTrace)) else c.NOTHING
示例#29
0
def plusSeconds(givenDateTime, seconds=None, deltaInSeconds=None):
    if ObjectHelper.isNotNone(seconds):
        deltaInMinutes = datetime.timedelta(seconds=seconds)
    if isinstance(givenDateTime, datetime.time):
        givenDateTime = forcedlyParse(f'{str(dateNow())} {givenDateTime}')
    return forcedlyGetDateTime(str(givenDateTime)) + deltaInMinutes
def handleBefore(resourceInstanceMethod, actionClass, args, kwargs, returns, inspectGlobals) :
    LogHelper.test(resourceInstanceMethod, 'Test started')
    actionHandlerException = handle(resourceInstanceMethod, actionClass, args, kwargs, returns, BEFORE_THE_TEST, RETURN_VALUE_FROM_CALL_BEFORE)
    if ObjectHelper.isNotNone(actionHandlerException) :
        raise actionHandlerException
    inspectGlobalsIfNeeded(inspectGlobals, resourceInstanceMethod, 'will run')