def getExceptionMessage(exception) : if ObjectHelper.isEmpty(exception) : return c.UNKNOWN exceptionAsString = str(exception) if c.NOTHING == exceptionAsString : return ReflectionHelper.getName(exception.__class__) else : return exceptionAsString
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 ]
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
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 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 getTestModuleNames(runOnly, ignore, globalsInstance): testsToRun = [] if ObjectHelper.isNone( runOnly) or ObjectHelper.isNotCollection(runOnly) else runOnly testsToIgnore = [] if ObjectHelper.isNone( ignore) or ObjectHelper.isNotCollection(ignore) else ignore runSpecificTests = ObjectHelper.isNotEmpty(testsToRun) LogHelper.prettyPython(getTestModuleNames, f'runSpecificTests: {runSpecificTests}, testsToRun', testsToRun, logLevel=LogHelper.TEST) testModuleNames = [] if ObjectHelper.isEmpty(testsToRun): testQueryTree = SettingHelper.querySetting(TEST_PACKAGE, globalsInstance.apiTree) LogHelper.prettyPython(getTestModuleNames, 'Test query tree', testQueryTree, logLevel=LogHelper.TEST) testModuleNames += getTestModuleNamesFromQuerryTree( testQueryTree, runOnly, ignore) else: for testName in testsToIgnore: if testName in testsToRun: testModuleNames, testsToRun, runSpecificTests.remove(testName) for testName in testsToRun: testNameSplitted = testName.split(c.DOT) testModuleName = c.NOTHING if 2 == len(testNameSplitted): testModuleName = testNameSplitted[-2] if testModuleName not in testModuleNames and StringHelper.isNotBlank( testName): testModuleNames.append(testModuleName) LogHelper.prettyPython(getTestModuleNames, 'Test module names', testModuleNames, logLevel=LogHelper.TEST) return testModuleNames, testsToRun, runSpecificTests
def getUndefindeName(typeThing): if ObjectHelper.isEmpty(typeThing): return f'({UNDEFINED})' else: return f'({typeThing} {UNDEFINED})'