Loading parseTestResults.py +32 −18 Original line number Diff line number Diff line Loading @@ -38,9 +38,20 @@ 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() Loading @@ -48,8 +59,11 @@ class TestOutputParser: ew.writeTestEntry(entry) ew.save() def createTestEntry(xmlObj): 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) Loading @@ -62,7 +76,7 @@ def createTestEntry(xmlObj): errorMsg = cts[0] if len(cts) > 0 else "" result = statusObj["status"] return TestEntry(testId, name, result, errorMsg) return TestEntry(testId, name, result, errorMsg, self.api, self.robotFile) def display_usage(): print(usage_str) Loading testEntry.py +5 −3 Original line number Diff line number Diff line 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 Loading @@ -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 writeExcel.py +11 −3 Original line number Diff line number Diff line Loading @@ -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: Loading @@ -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 Loading @@ -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] Loading Loading
parseTestResults.py +32 −18 Original line number Diff line number Diff line Loading @@ -38,9 +38,20 @@ 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() Loading @@ -48,8 +59,11 @@ class TestOutputParser: ew.writeTestEntry(entry) ew.save() def createTestEntry(xmlObj): 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) Loading @@ -62,7 +76,7 @@ def createTestEntry(xmlObj): errorMsg = cts[0] if len(cts) > 0 else "" result = statusObj["status"] return TestEntry(testId, name, result, errorMsg) return TestEntry(testId, name, result, errorMsg, self.api, self.robotFile) def display_usage(): print(usage_str) Loading
testEntry.py +5 −3 Original line number Diff line number Diff line 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 Loading @@ -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
writeExcel.py +11 −3 Original line number Diff line number Diff line Loading @@ -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: Loading @@ -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 Loading @@ -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] Loading