Skip to content

Commit

Permalink
Merge pull request TriBITSPub#409 from bartlettroscoe/sesw-383-missin…
Browse files Browse the repository at this point in the history
…g-test-status-field

Add getTestDictStatusField() to handle empty 'status' field (SESW-383)
  • Loading branch information
bartlettroscoe authored Aug 24, 2021
2 parents 548861d + d64b813 commit b87f926
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
30 changes: 27 additions & 3 deletions test/ci_support/CDashQueryAnalyzeReport_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,16 @@ def test_getAndCacheCDashQueryDataOrReadFromCache_write_cache(self):
extractCDashApiQueryData_in=mockExtractCDashApiQueryDataFunctor
)
self.assertEqual(cdashQueryData, g_getAndCacheCDashQueryDataOrReadFromCache_data)
cdashQueryData_cache = eval(open(outputCacheFile, 'r').read())
with open(outputCacheFile, 'r') as inFile:
cdashQueryData_cache = eval(inFile.read())
self.assertEqual(cdashQueryData_cache, g_getAndCacheCDashQueryDataOrReadFromCache_data)

def test_getAndCacheCDashQueryDataOrReadFromCache_read_cache(self):
outputCacheDir="test_getAndCacheCDashQueryDataOrReadFromCache_read_cache"
outputCacheFile=outputCacheDir+"/cachedCDashQueryData.json"
deleteThenCreateTestDir(outputCacheDir)
open(outputCacheFile, 'w').write(str(g_getAndCacheCDashQueryDataOrReadFromCache_data))
with open(outputCacheFile, 'w') as outFile:
outFile.write(str(g_getAndCacheCDashQueryDataOrReadFromCache_data))
cdashQueryData = getAndCacheCDashQueryDataOrReadFromCache(
"dummy-cdash-url", outputCacheFile,
useCachedCDashData=True,
Expand All @@ -946,7 +948,8 @@ def test_getAndCacheCDashQueryDataOrReadFromCache_always_read_cache(self):
outputCacheDir="test_getAndCacheCDashQueryDataOrReadFromCache_always_read_cache"
outputCacheFile=outputCacheDir+"/cachedCDashQueryData.json"
deleteThenCreateTestDir(outputCacheDir)
open(outputCacheFile, 'w').write(str(g_getAndCacheCDashQueryDataOrReadFromCache_data))
with open(outputCacheFile, 'w') as outFile:
outFile.write(str(g_getAndCacheCDashQueryDataOrReadFromCache_data))
cdashQueryData = getAndCacheCDashQueryDataOrReadFromCache(
"dummy-cdash-url", outputCacheFile,
useCachedCDashData=True,
Expand Down Expand Up @@ -2229,6 +2232,27 @@ def test_mdt_missing_and_failed(self):
self.assertEqual(testHistoryStats['previous_nopass_date'], '2000-12-30') # Shifted!
self.assertEqual(testStatus, 'Missing')

def test_empty_1_pass_2_failed_2(self):
testHistoryLOD = getTestHistoryLOD5(['ToBeRemoved','Passed','Failed','Passed','Failed'])
testDictWithStatusToBeRemoved = \
next((item for item in testHistoryLOD if item['status']=='ToBeRemoved'), None)
del testDictWithStatusToBeRemoved['status']
currentTestDate = "2001-01-01"
testingDayStartTimeUtc = "00:00"
daysOfHistory = 5
(sortedTestHistoryLOD, testHistoryStats, testStatus) = \
sortTestHistoryGetStatistics(testHistoryLOD, currentTestDate,
testingDayStartTimeUtc, daysOfHistory)
self.assertEqual(sortedTestHistoryLOD[0]['buildstarttime'],'2001-01-01T05:54:03 UTC')
self.assertEqual(testHistoryStats['pass_last_x_days'], 2)
self.assertEqual(testHistoryStats['nopass_last_x_days'], 3)
self.assertEqual(testHistoryStats['missing_last_x_days'], 0)
self.assertEqual(testHistoryStats['consec_pass_days'], 0)
self.assertEqual(testHistoryStats['consec_nopass_days'], 1)
self.assertEqual(testHistoryStats['consec_missing_days'], 0)
self.assertEqual(testHistoryStats['previous_nopass_date'], '2000-12-30')
self.assertEqual(testStatus, 'Not Run')


#############################################################################
#
Expand Down
15 changes: 12 additions & 3 deletions tribits/ci_support/CDashQueryAnalyzeReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ def getStandardTestsetTypeInfo(testsetAcro, testsetColor=None):
return tsti


# Return the 'status' field from a test dict
#
# Return 'Not Run' if the 'status' field is missing. (This happens with one
# customer's tests apparently, see SESW-383.)
#
def getTestDictStatusField(testDict):
return testDict.get('status', 'Not Run')


# Get the Test-set acronym from the fields of a test dict
#
def getTestsetAcroFromTestDict(testDict):
Expand Down Expand Up @@ -1447,10 +1456,10 @@ def decr(testDict, key): testDict[key] = testDict[key] - 1

# testStatus (for this test based on history)
if topTestDictTestingDayDT == currentTestDateDT:
testStatus = topTestDict['status']
testStatus = getTestDictStatusField(topTestDict)
else:
testStatus = "Missing"
#print("testStatus = "+testStatus)
#print("testStatus = '"+testStatus+"'")

# testHistoryStats

Expand All @@ -1474,7 +1483,7 @@ def decr(testDict, key): testDict[key] = testDict[key] - 1

# Loop over test history for each of the kth entries and update quantities
for pastTestDict_k in sortedTestHistoryLOD:
pastTestStatus_k = pastTestDict_k['status']
pastTestStatus_k = getTestDictStatusField(pastTestDict_k)
pastTestDateUtc_k = testingDayTimeObj.getTestingDayDateFromBuildStartTimeStr(
pastTestDict_k['buildstarttime'])
# Count the initial consecutive streaks for passing and nonpassing
Expand Down

0 comments on commit b87f926

Please sign in to comment.