Skip to content
Snippets Groups Projects
Commit c08d321f authored by brydenf's avatar brydenf
Browse files

Added 2 columns to TestEntry: NFV API and Robot file

parent f8e87a16
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,8 @@ Usage
python parseTestResults.py output.xml
where output.xml is the xml file generated by robot
The command outputs to a new xlslx file if it does not exist, or
appends to an existing one.
"""
......@@ -38,32 +38,46 @@ class TestOutputParser:
def run_parser(self):
soup = BeautifulSoup(self.contents, "lxml")
# Suite information
suite = soup.find("suite")
path = suite["source"]
# TODO This might be an issue later on. In Unix-style paths the separator is a forward slash
parts = path.split("\\")
# Extract info for test entries
self.api = parts[len(parts) - 2]
self.robotFile = parts[len(parts) - 1]
# Tests
tests = soup.find_all("test")
for test in tests:
self.testEntries.append(createTestEntry(test))
self.testEntries.append(self.createTestEntry(test))
# Write tests
ew = ExcelWriter()
for entry in self.testEntries:
ew.writeTestEntry(entry)
ew.save()
def createTestEntry(self, xmlObj):
"""
Takes the xml entry corresponding to the test from the output file,
and returns a TestEntry object with the relevant information extracted.
"""
# retrieve ID and name
idRaw = xmlObj.find("doc", recursive=False).contents
mg = re.search(r"Test ID: ([0-9\.]*)$", idRaw[0].string, re.MULTILINE)
testId = mg.group(1)
name = xmlObj["name"]
#retrieve status and error message (if FAIL)
statusObj = xmlObj.find("status", recursive=False)
cts = statusObj.contents
errorMsg = cts[0] if len(cts) > 0 else ""
def createTestEntry(xmlObj):
# retrieve ID and name
idRaw = xmlObj.find("doc", recursive=False).contents
mg = re.search(r"Test ID: ([0-9\.]*)$", idRaw[0].string, re.MULTILINE)
testId = mg.group(1)
name = xmlObj["name"]
#retrieve status and error message (if FAIL)
statusObj = xmlObj.find("status", recursive=False)
cts = statusObj.contents
errorMsg = cts[0] if len(cts) > 0 else ""
result = statusObj["status"]
return TestEntry(testId, name, result, errorMsg)
result = statusObj["status"]
return TestEntry(testId, name, result, errorMsg, self.api, self.robotFile)
def display_usage():
print(usage_str)
......
class TestEntry:
def __init__(self, id, name, result, errorMsg=""):
def __init__(self, id, name, result, errorMsg, api, robotFile):
self.id = id
self.name = name
self.result = result
self.errorMsg = errorMsg
self.api = api
self.robotFile = robotFile
def __str__(self):
baseStr = "[{}] {}:{}".format(self.id, self.name, self.result)
if self.errorMsg != "":
return "{}: {}".format(baseStr, self.errorMsg)
return "{}: {} ({}/{})".format(baseStr, self.errorMsg, self.api, self.robotFile)
else:
return baseStr
......@@ -16,4 +18,4 @@ class TestEntry:
return "{}: {}".format(self.name, self.result)
def asList(self):
return [self.id, self.name, self.result, self.errorMsg]
\ No newline at end of file
return [self.id, self.name, self.result, self.errorMsg, self.api, self.robotFile]
\ No newline at end of file
......@@ -16,6 +16,13 @@ class ExcelWriter:
self.wb = getWorkbook()
self.ws = self.wb.active
def getEntryWithId(self, id):
"""
When inserting an entry, it might be a test being re-run. In that case,
the row containing that test needs to be updated, as opposed to appending
the entry to the end of the file.
"""
def getLastRow(self):
for cell in self.ws["A"]:
if cell.value is None:
......@@ -25,7 +32,8 @@ class ExcelWriter:
def writeTestEntry(self, testEntry):
lastRow = self.getLastRow()
cellCol = ExcelWriter.PASS_COL if testEntry.result == "PASS" else ExcelWriter.FAIL_COL
for col, cellValue in zip(self.ws.iter_cols(min_row=lastRow, max_col=4, max_row=lastRow), testEntry.asList()):
entryVals = testEntry.asList()
for col, cellValue in zip(self.ws.iter_cols(min_row=lastRow, max_col=len(entryVals), max_row=lastRow), entryVals):
for cell in col:
cell.value = cellValue
cell.fill = PatternFill("solid", fgColor=cellCol)# cellCol
......@@ -37,10 +45,10 @@ def initWorkbook(wb):
"""
Writes column headers to ws
"""
headers = [("Test ID", 10), ("Test name", 80), ("Result", 6), ("Error Message", 100)]
headers = [("Test ID", 10), ("Test name", 80), ("Result", 6), ("Error Message", 100), ("NFV API", 25), ("Robot Test File", 25)]
headerFont = Font(bold=True)
ws = wb.active
for col, header in zip(ws.iter_cols(min_row=1, max_col=4, max_row=1), headers):
for col, header in zip(ws.iter_cols(min_row=1, max_col=len(headers), max_row=1), headers):
for cell in col:
headerName = header[0]
colsize = header[1]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment