def leftEqual(left, right, visitedIdInstances, muteLogs=True) : if ObjectHelper.isNone(left) or ObjectHelper.isNone(right) : return left is None and right is None isEqual = True leftIsCollection = ObjectHelper.isCollection(left) rightIsCollection = ObjectHelper.isCollection(right) if leftIsCollection and rightIsCollection : if len(left) == len(right) : for itemLeft, itemRight in zip(left, right) : if isEqual : isEqual = isEqual and ObjectHelper.equals(itemLeft, itemRight, visitedIdInstances=visitedIdInstances, muteLogs=muteLogs) else : break return isEqual else : return False elif (leftIsCollection and not rightIsCollection) or (not leftIsCollection and rightIsCollection) : return False else : attrinuteDataList = ReflectionHelper.getAttributeDataList(left) if not muteLogs : LogHelper.prettyPython(leftEqual, f'{left} data list', attrinuteDataList, logLevel=LogHelper.DEBUG, condition=not muteLogs) if 0 == len(attrinuteDataList) : return False for value, name in attrinuteDataList : if isEqual : isEqual = isEqual and ObjectHelper.equals(value, ReflectionHelper.getAttributeOrMethod(right, name), visitedIdInstances=visitedIdInstances, muteLogs=muteLogs) else : break return isEqual
def getTestModuleNamesFromQuerryTree(testQueryTree, runOnly, ignore): testModuleNames = [] for queryResultKey, queryResult in testQueryTree.items(): LogHelper.prettyPython(getTestModuleNamesFromQuerryTree, 'Query result', queryResult, logLevel=LogHelper.TEST) updateTestModuleNames(testModuleNames, queryResult, runOnly, ignore) return testModuleNames
def tddModule(testName, testModule, dataList, times, runSpecificTests, testsToRun, allShouldRun, someShouldRun, logResult): import globals tddModuleGlobalsInstance = globals.newGlobalsInstance( testModule.__file__, successStatus=globalsInstance.successStatus, errorStatus=globalsInstance.errorStatus, settingStatus=globalsInstance.settingStatus or inspectGlobals, debugStatus=globalsInstance.debugStatus, warningStatus=globalsInstance.warningStatus, wrapperStatus=globalsInstance.wrapperStatus, testStatus=globalsInstance.testStatus, logStatus=globalsInstance.logStatus) LogHelper.test(tddModule, f'{testName} started') testReturns = {} testTime = 0 for data in dataList: testMustRun = isTestToRun(testModule, data, runSpecificTests, testsToRun) LogHelper.prettyPython(tddModule, f'test attribute or method', data[0], logLevel=LogHelper.TEST) LogHelper.prettyPython(tddModule, f'isTestToRun', testMustRun, logLevel=LogHelper.TEST) if testMustRun: for index in range(times): testTimeStart = time.time() if times - 1 == index: runnableUnitTest = getUnitTest(inspectGlobals, globalsInstance) testName, data, testReturns, someDidRun, logResult, discountTimeEnd = runnableUnitTest( testModule, testName, data, testReturns, logResult) else: runnableUnitTestBatch = getUnitTestBatch( inspectGlobals, globalsInstance) discountTimeEnd = runnableUnitTestBatch( testModule, data) testTime += time.time() - discountTimeEnd else: allDidRun = False if not allShouldRun == allDidRun and someShouldRun == someDidRun: amountAlthought = getAmmount(allShouldRun, someShouldRun) shouldOrShouldnt = getShouldOrShouldntAsString( allShouldRun, someShouldRun) amountAfterAlthought = getAmmount(allDidRun, someDidRun) didOrDidnt = getSomeDidOrDidntAsString(allDidRun, someDidRun) errorMessage = f'Inconsistenc{StringHelper.getS(allShouldRun or someShouldRun, es=True)} detected. Although {amountAlthought} test{StringHelper.getS(allShouldRun or someShouldRun)} {shouldOrShouldnt} run, {amountAfterAlthought} {didOrDidnt} run' exception = Exception(errorMessage) raise exception return allDidRun, someDidRun, testTime, testReturns
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 getItNaked(it): printDetails(it) printClass(it) try: LogHelper.prettyPython(getAttributeDataDictionary, 'getAttributeDataDictionary', getAttributePointerList(it), logLevel=LogHelper.DEBUG) except: pass try: LogHelper.prettyPython(getAttributeAndMethodNameList, 'getAttributeAndMethodNameList', getAttributeAndMethodNameList(it), logLevel=LogHelper.DEBUG) except: pass try: LogHelper.prettyPython(getAttributeNameList, 'getAttributeNameList', getAttributeNameList(it), logLevel=LogHelper.DEBUG) except: pass try: LogHelper.prettyPython(getAttributeDataList, 'getAttributeDataList', getAttributeDataList(it), logLevel=LogHelper.DEBUG) except: pass try: LogHelper.prettyPython(getAttributeDataDictionary, 'getAttributeDataDictionary', getAttributeDataDictionary(it), logLevel=LogHelper.DEBUG) except: pass
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 equals(expected, toAssert, ignoreKeyList=None, ignoreCharactereList=None, visitedIdInstances=None, muteLogs=True): if isNone(expected) or isNone(toAssert): return expected is None and toAssert is None if isNativeClass(type(expected)): return expected == toAssert if isNone(visitedIdInstances): visitedIdInstances = [] if isDictionary(expected) and isDictionary(toAssert): innerIgnoreCharactereList = [c.SPACE] if isNotNone(ignoreCharactereList): innerIgnoreCharactereList += ignoreCharactereList filteredResponse = StringHelper.filterJson( str(sortIt(filterIgnoreKeyList(expected, ignoreKeyList))), extraCharacterList=innerIgnoreCharactereList) filteredExpectedResponse = StringHelper.filterJson( str(sortIt(filterIgnoreKeyList(toAssert, ignoreKeyList))), extraCharacterList=innerIgnoreCharactereList) return filteredResponse == filteredExpectedResponse elif isCollection(expected) and isCollection(toAssert): areEquals = True try: for a, b in zip(expected, toAssert): areEquals = equals(a, b, ignoreKeyList=ignoreKeyList, ignoreCharactereList=ignoreCharactereList, visitedIdInstances=visitedIdInstances, muteLogs=muteLogs) if not areEquals: break return areEquals except Exception as exception: areEquals = False LogHelper.log( equals, f'Different arguments in {expected} and {toAssert}. Returning "{areEquals}" by default', exception=exception) else: if isNotNone(toAssert) and id(toAssert) not in visitedIdInstances: areEquals = True try: if not muteLogs: LogHelper.prettyPython(equals, f'expected', expected, logLevel=LogHelper.DEBUG, condition=not muteLogs) LogHelper.prettyPython(equals, f'toAssert', toAssert, logLevel=LogHelper.DEBUG, condition=not muteLogs) areEquals = True and ObjectHelperHelper.leftEqual( expected, toAssert, visitedIdInstances, muteLogs=muteLogs) and ObjectHelperHelper.leftEqual( toAssert, expected, visitedIdInstances, muteLogs=muteLogs) except Exception as exception: areEquals = False LogHelper.log( equals, f'Different arguments in {expected} and {toAssert}. Returning "{areEquals}" by default', exception=exception) visitedIdInstances.append(id(toAssert)) return areEquals else: return True