def validateCmndLineOptions(inOptions): if inOptions.date == "": print "Error, can't have empty --date, must pass in --date=YYYY-MM-DD!" sys.exit(1) else: CDQAR.validateAndConvertYYYYMMDD(inOptions.date)
def readCsvFileIntoDictOfLists(csvFileName, colNameAndTypeList): dictOfLists = {} with open(csvFileName, 'r') as csvFile: csvReader = csv.reader(csvFile) # Get the list of col headers and the index to the col headers we want columnHeadersList = \ CDQAR.getColumnHeadersFromCsvFileReader(csvFileName, csvReader) if len(columnHeadersList) == 0: # File is empty so just return an empty distOfLists! return dictOfLists colNameTypeIdxList = \ getColNameTypeIdxListGivenColNameAndTypeList(csvFileName, columnHeadersList, colNameAndTypeList) # Initial empty lists for each column to hold the data for colNameTypeIdx in colNameTypeIdxList: dictOfLists.update( { colNameTypeIdx.colName() : [] } ) # Fill the columns of data dataRowIdx = 0 for lineList in csvReader: if not lineList: continue # Ignore blank line CDQAR.stripWhiltespaceFromStrList(lineList) assertNumExpectedCsvFileLineEntries(csvFileName, columnHeadersList, dataRowIdx, lineList) # Read the row entries for colNameTypeIdx in colNameTypeIdxList: dictOfLists[colNameTypeIdx.colName()].append( colNameTypeIdx.convertFromStr(lineList[colNameTypeIdx.getIdx()]) ) # Update for next row dataRowIdx += 1 # Return completed dict of lists return dictOfLists
def writeNewTestsWithIssueTrackersFile(self, uniqNonpassingTestsLOD): if self.options.newTestsWithIssueTrackersFile: print("\nWriting out list of test/biuld pairs for CSV file '"\ +self.options.newTestsWithIssueTrackersFile+"'") csvFileStruct = CDQAR.writeTestsLODToCsvFileStructure( uniqNonpassingTestsLOD, self.issueTrackerUrlTemplate, self.issueTrackerTemplate) with open(self.options.newTestsWithIssueTrackersFile, 'w') as csvFile: csvFile.write(CDQAR.writeCsvFileStructureToStr(csvFileStruct))
def setExtraCmndLineOptionsAfterParse(inOptions_inout): setattr( inOptions_inout, 'filterOutBuildsAndTestsNotMatchingExpectedBuilds', inOptions_inout.filterOutBuildsAndTestsNotMatchingExpectedBuildsStr == "on") setattr(inOptions_inout, 'useCachedCDashData', inOptions_inout.useCachedCDashDataStr == "on") setattr(inOptions_inout, 'requireTestHistoryMatchNonpassingTests', inOptions_inout.requireTestHistoryMatchNonpassingTestsStr == "on") setattr(inOptions_inout, 'printDetails', inOptions_inout.printDetailsStr == "on") setattr(inOptions_inout, 'listUnexpectedBuilds', inOptions_inout.listUnexpectedBuildsStr == "on") if inOptions_inout.cdashBaseCacheFilesPrefix == "": inOptions_inout.cdashBaseCacheFilesPrefix = \ CDQAR.getFileNameStrFromText(inOptions_inout.buildSetName)+"_" setattr(inOptions_inout, 'emailWithoutSoftHyphens', inOptions_inout.emailWithoutSoftHyphensStr == "on")
def testSetGetDataAnalyzeReport( self, testSetType, testSetDescr, testSetAcro, testSetTotalSize, testSetLOD, testSetNonzeroSizeTriggerGlobalFail=True, colorTestSet=None, # Change to one of the supported colors sortTests=True, limitTableRows=None, # Change to 'int' > 0 to limit to this this getTestHistory=False, ): print("") testSetSummaryStr = CDQAR.getCDashDataSummaryHtmlTableTitleStr(testSetDescr, testSetAcro, testSetTotalSize) print(testSetSummaryStr) if testSetTotalSize > 0: self.overallVars.globalPass = False self.overallVars.summaryLineDataNumbersList.append( testSetAcro+"="+str(testSetTotalSize)) self.overallVars.htmlEmailBodyTop += \ CDQAR.colorHtmlText(testSetSummaryStr, colorTestSet)+"<br>\n" if sortTests or limitTableRows: testSetSortedLimitedLOD = CDQAR.sortAndLimitListOfDicts( testSetLOD, self.testsSortOrder, limitTableRows ) else: testSetSortedLimitedLOD = testSetLOD sio = self.inOptions if getTestHistory: CDQAR.foreachTransform( testSetSortedLimitedLOD, CDQAR.AddTestHistoryToTestDictFunctor( cdashUrl=sio.cdashSiteUrl, projectName=sio.cdashProjectName, date=sio.date, testingDayStartTimeUtc=sio.cdashProjectTestingDayStartTime, daysOfHistory=sio.testHistoryDays, testCacheDir=self.testHistoryCacheDir, useCachedCDashData=sio.useCachedCDashData, alwaysUseCacheFileIfExists=True, verbose=True, printDetails=sio.printDetails, requireMatchTestTopTestHistory=sio.requireTestHistoryMatchNonpassingTests, ) ) self.overallVars.htmlEmailBodyBottom += CDQAR.createCDashTestHtmlTableStr( testSetType, testSetDescr, testSetAcro, testSetTotalSize, testSetSortedLimitedLOD, sio.testHistoryDays, limitRowsToDisplay=limitTableRows, testSetColor=colorTestSet )
def validateAndConvertCmndLineOptions(inOptions): if inOptions.date == "": print("Error, can't have empty --date, must pass in --date=YYYY-MM-DD"+\ " or special values --date=today or --date=yesterday!") sys.exit(1) else: dateTimeObj = CDQAR.convertInputDateArgToYYYYMMDD( inOptions.cdashProjectTestingDayStartTime, inOptions.date) inOptions.date = CBTD.getDateStrFromDateTime(dateTimeObj)
def getTestHistory(self, testLOD): sio = self.inOptions CDQAR.foreachTransform( testLOD, CDQAR.AddTestHistoryToTestDictFunctor( cdashUrl=sio.cdashSiteUrl, projectName=sio.cdashProjectName, date=sio.date, testingDayStartTimeUtc=sio.cdashProjectTestingDayStartTime, daysOfHistory=sio.testHistoryDays, testCacheDir=self.testHistoryCacheDir, useCachedCDashData=sio.useCachedCDashData, alwaysUseCacheFileIfExists=True, verbose=True, printDetails=sio.printDetails, requireMatchTestTopTestHistory=sio. requireTestHistoryMatchNonpassingTests, ))
def downloadNonpassingTestsData(self): apiQueryTestsUrl = self.options.nonpassingTestsUrl.replace( "/queryTests.php", "/api/v1/queryTests.php") cdashDownloadFileForTesting = \ os.environ.get('CREATE_ISSUE_TRACKER_FROM_CDASH_QUERY_FILE_FOR_UNIT_TESTING', '' ) nonpassingTestsLOD = \ CDQAR.downloadTestsOffCDashQueryTestsAndFlatten(apiQueryTestsUrl, fullCDashQueryTestsJsonCacheFile=cdashDownloadFileForTesting, alwaysUseCacheFileIfExists=True ) return nonpassingTestsLOD
def getUniqueTestsListOfDicts(cdashTestsLOD): # Get a dict that has just unique keys 'site', 'buildName' and 'testname' values uniqTestDict = {} for testDict in cdashTestsLOD: site = testDict.get('site') buildName = testDict.get('buildName') testname = testDict.get('testname') uniqTestDict.update({ site + "_" + buildName + "_" + testname: { 'site': site, 'buildName': buildName, 'testname': testname } }) # Get a flat last of test dicts uniqNonpassingTestsLOD = [] for key, value in distItems(uniqTestDict): uniqNonpassingTestsLOD.append(value) uniqNonpassingTestsLOD = CDQAR.sortAndLimitListOfDicts( uniqNonpassingTestsLOD, CDQAR.getDefaultTestDictsSortKeyList()) return uniqNonpassingTestsLOD
def setExtraCmndLineOptionsAfterParse(inOptions_inout): if inOptions_inout.useCachedCDashDataStr == "on": setattr(inOptions_inout, 'useCachedCDashData', True) else: setattr(inOptions_inout, 'useCachedCDashData', False) if inOptions_inout.printDetailsStr == "on": setattr(inOptions_inout, 'printDetails', True) else: setattr(inOptions_inout, 'printDetails', False) if inOptions_inout.cdashBaseCacheFilesPrefix == "": inOptions_inout.cdashBaseCacheFilesPrefix = \ CDQAR.getFileNameStrFromText(inOptions_inout.buildSetName)+"_"
def testSetGetDataAnalyzeReport( self, testSetType, testSetDescr, testSetAcro, testSetTotalSize, testSetLOD, testSetNonzeroSizeTriggerGlobalFail=True, colorTestSet=None, # Change to one of the supported colors sortTests=True, limitTableRows=None, # Change to 'int' > 0 to limit to this this getTestHistory=False, ): print("") testSetSummaryStr = CDQAR.getCDashDataSummaryHtmlTableTitleStr(testSetDescr, testSetAcro, testSetTotalSize) print(testSetSummaryStr) if testSetTotalSize > 0: self.overallVars.globalPass = False self.overallVars.summaryLineDataNumbersList.append( testSetAcro+"="+str(testSetTotalSize)) self.overallVars.htmlEmailBodyTop += \ CDQAR.colorHtmlText(testSetSummaryStr, colorTestSet)+"<br>\n" if sortTests or limitTableRows: testSetSortedLimitedLOD = CDQAR.sortAndLimitListOfDicts( testSetLOD, self.testsSortOrder, limitTableRows ) else: testSetSortedLimitedLOD = testSetLOD if getTestHistory: CDQAR.foreachTransform( testSetSortedLimitedLOD, CDQAR.AddTestHistoryToTestDictFunctor( self.inOptions.cdashSiteUrl, self.inOptions.cdashProjectName, self.inOptions.date, self.inOptions.testHistoryDays, self.testHistoryCacheDir, useCachedCDashData=self.inOptions.useCachedCDashData, alwaysUseCacheFileIfExists=True, verbose=True, printDetails=self.inOptions.printDetails, ) ) self.overallVars.htmlEmailBodyBottom += CDQAR.createCDashTestHtmlTableStr( testSetType, testSetDescr, testSetAcro, testSetTotalSize, testSetSortedLimitedLOD, self.inOptions.testHistoryDays, limitRowsToDisplay=limitTableRows, testSetColor=colorTestSet )
def robustReadCsvFileIntoListOfDicts(csvFile): listOfDicts = None errMsg = "" if os.path.exists(csvFile): try: listOfDicts = CDQAR.readCsvFileIntoListOfDicts(csvFile) except Exception as exceptObj: if str(exceptObj).find("is empty which is not allowed") != -1: errMsg = csvFile + ": ERROR: File is empty!" else: errMsg = csvFile + ": ERROR: " + str(exceptObj) # NOTE: The above check is tied pretty tighlty to the implementation of # readCsvFileIntoListOfDicts() in looking for a specific substring in # the error message but it will still capture any other error as well # and report it through errMsg. else: errMsg = csvFile + ": ERROR: File does not exist!" return (listOfDicts, errMsg)
# Beginning of top full bulid and tests CDash links paragraph overallVars.htmlEmailBodyTop += "<p>\n" # # D.1) Read data from input files, set up cache directories # # Assert this data is correct and abort if there is an error before we run # expensive CDash queries! # # Get list of expected builds from input CSV file expectedBuildsLOD = [] if inOptions.expectedBuildsFile: expectedBuildsLOD = \ CDQAR.getExpectedBuildsListfromCsvFile(inOptions.expectedBuildsFile) print("\nNum expected builds = "+str(len(expectedBuildsLOD))) # Create a SearchableListOfDicts that will look up an expected build given # just a test dict fields ['site', 'buildName']. (The list of tests with # issue trackers does not have 'group' since cdash/queryTests.php does not # give the 'group' associated with each test. Also, note that we need # this special SearchableListOfDicts since the Build Name key name # different for a cdash/queryTests.php test dict 'buildName' and a # cdash/index.php build dict 'buildname'.) testsToExpectedBuildsSLOD = \ CDQAR.createTestToBuildSearchableListOfDicts(expectedBuildsLOD) # ToDo: Put in try/except to print about error in duplicate rows in the # list of expected builds. # Get list of tests with issue trackers from the input CSV file
# Beginning of top full bulid and tests CDash links paragraph overallVars.htmlEmailBodyTop += "<p>\n" # # D.1) Read data from input files, set up cache directories # # Assert this data is correct and abort if there is an error before we run # expensive CDash queries! # # Get list of expected builds from input CSV file expectedBuildsLOD = [] if inOptions.expectedBuildsFile: expectedBuildsLOD = \ CDQAR.getExpectedBuildsListfromCsvFile(inOptions.expectedBuildsFile) print("\nNum expected builds = " + str(len(expectedBuildsLOD))) # Create a SearchableListOfDicts that will look up an expected build given # just a test dict fields ['site', 'buildName']. (The list of tests with # issue trackers does not have 'group' since cdash/queryTests.php does not # give the 'group' associated with each test. Also, note that we need # this special SearchableListOfDicts since the Build Name key name # different for a cdash/queryTests.php test dict 'buildName' and a # cdash/index.php build dict 'buildname'.) testsToExpectedBuildsSLOD = \ CDQAR.createTestToBuildSearchableListOfDicts(expectedBuildsLOD) # ToDo: Put in try/except to print about error in duplicate rows in the # list of expected builds. # Get list of tests with issue trackers from the input CSV file
# # B) Sound off # print("***") print("*** Query and analyze CDash results for "+inOptions.buildSetName+\ " for testing day "+inOptions.date) print("***") # # C) Create beginning of email body (that does not require getting any data off CDash) # # Aggregation of vars that get updated in this main() body and by functions # called. cdashReportData = CDQAR.CDashReportData() cdashReportData.htmlEmailBodyTop += \ "<h2>Build and Test results for "+inOptions.buildSetName \ +" on "+inOptions.date+"</h2>\n\n" # # D) Read data files, get data off of CDash, do analysis, and construct HTML # body parts # try: # Beginning of top full build and tests CDash links paragraph cdashReportData.htmlEmailBodyTop += "<p>\n"