Loading scripts/parse_xml_report.py +34 −11 Original line number Diff line number Diff line Loading @@ -4,12 +4,20 @@ import argparse import pandas as pd from xml.etree import ElementTree from collections import Counter from typing import Optional from enum import Enum SPLIT_STRING = "_split" WHOLE_STRING = "_whole" class Result(str, Enum): ERROR = "ERROR" FAIL = "FAIL" PASS = "PASS" class TestcaseParser(dict): def __init__(self, testcases: list): super().__init__() Loading @@ -32,8 +40,8 @@ class TestcaseParser(dict): # if we already have this testcase, do a sanity check and set result to ERROR if fulltestname in self: results = [self[fulltestname]["result"], result] assert any(r == "ERROR" for r in results) self[fulltestname]["result"] = "ERROR" assert any(r == Result.ERROR for r in results) self[fulltestname]["result"] = Result.ERROR return ret = {} Loading Loading @@ -110,24 +118,33 @@ def xml_to_dataframe(xml_report: str) -> pd.DataFrame: def get_result_from_testcase(testcase: ElementTree.Element) -> str: if testcase.find("failure") is not None: testresult = "FAIL" testresult = Result.FAIL elif testcase.find("error") is not None: testresult = "ERROR" testresult = Result.ERROR else: testresult = "PASS" testresult = Result.PASS return testresult def main(xml_report, csv_file): def main(xml_report: str, csv_file: str, split_csv_file: Optional[str]): df = xml_to_dataframe(xml_report) df.to_csv(csv_file, index=False) n_testcases = len(df) count = Counter(df["result"]) if split_csv_file is not None: mask_errors = df["result"] == Result.ERROR mask_whole = df["split"] == "whole" mask_single = mask_errors | mask_whole df_split = df[~mask_single] df_split.to_csv(split_csv_file, index=False) df = df[mask_single] df.to_csv(csv_file, index=False) print( f"Parsed testsuite with {n_testcases} tests: {count['PASS']} passes, {count['FAIL']} failures and {count['ERROR']} errors." f"Parsed testsuite with {n_testcases} tests: {count[Result.PASS]} passes, {count[Result.FAIL]} failures and {count[Result.ERROR]} errors." ) Loading @@ -140,7 +157,13 @@ if __name__ == "__main__": type=str, help="XML junit report input file, e.g. report-junit.xml", ) parser.add_argument("csv_file", type=str, help="Output CSV file, e.g. report.csv") parser.add_argument("csv_file", help="Output CSV file, e.g. report.csv") parser.add_argument( "--split-csv-file", type=str, default=None, help="If given, write the split comparison values to this file separately", ) args = parser.parse_args() main(args.xml_report, args.csv_file) main(args.xml_report, args.csv_file, args.split_csv_file) Loading
scripts/parse_xml_report.py +34 −11 Original line number Diff line number Diff line Loading @@ -4,12 +4,20 @@ import argparse import pandas as pd from xml.etree import ElementTree from collections import Counter from typing import Optional from enum import Enum SPLIT_STRING = "_split" WHOLE_STRING = "_whole" class Result(str, Enum): ERROR = "ERROR" FAIL = "FAIL" PASS = "PASS" class TestcaseParser(dict): def __init__(self, testcases: list): super().__init__() Loading @@ -32,8 +40,8 @@ class TestcaseParser(dict): # if we already have this testcase, do a sanity check and set result to ERROR if fulltestname in self: results = [self[fulltestname]["result"], result] assert any(r == "ERROR" for r in results) self[fulltestname]["result"] = "ERROR" assert any(r == Result.ERROR for r in results) self[fulltestname]["result"] = Result.ERROR return ret = {} Loading Loading @@ -110,24 +118,33 @@ def xml_to_dataframe(xml_report: str) -> pd.DataFrame: def get_result_from_testcase(testcase: ElementTree.Element) -> str: if testcase.find("failure") is not None: testresult = "FAIL" testresult = Result.FAIL elif testcase.find("error") is not None: testresult = "ERROR" testresult = Result.ERROR else: testresult = "PASS" testresult = Result.PASS return testresult def main(xml_report, csv_file): def main(xml_report: str, csv_file: str, split_csv_file: Optional[str]): df = xml_to_dataframe(xml_report) df.to_csv(csv_file, index=False) n_testcases = len(df) count = Counter(df["result"]) if split_csv_file is not None: mask_errors = df["result"] == Result.ERROR mask_whole = df["split"] == "whole" mask_single = mask_errors | mask_whole df_split = df[~mask_single] df_split.to_csv(split_csv_file, index=False) df = df[mask_single] df.to_csv(csv_file, index=False) print( f"Parsed testsuite with {n_testcases} tests: {count['PASS']} passes, {count['FAIL']} failures and {count['ERROR']} errors." f"Parsed testsuite with {n_testcases} tests: {count[Result.PASS]} passes, {count[Result.FAIL]} failures and {count[Result.ERROR]} errors." ) Loading @@ -140,7 +157,13 @@ if __name__ == "__main__": type=str, help="XML junit report input file, e.g. report-junit.xml", ) parser.add_argument("csv_file", type=str, help="Output CSV file, e.g. report.csv") parser.add_argument("csv_file", help="Output CSV file, e.g. report.csv") parser.add_argument( "--split-csv-file", type=str, default=None, help="If given, write the split comparison values to this file separately", ) args = parser.parse_args() main(args.xml_report, args.csv_file) main(args.xml_report, args.csv_file, args.split_csv_file)