Commit ddec66ac authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'ci/refactor-histogram-creation' into kiene/tmp-branch-for-ltv-split-testing

parents 6379031b a50fb3b8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ def create_histograms(
            ax.set_xlabel(measure)
            if "DIFF" in measure:
                ax.set_xticks(range(len(x)), x, rotation=35)
            else:
                ax.set_xticks(range(len(x)), x)
            ax.set_ylabel("Number of test cases")

            fig.set_figheight(4)
@@ -127,6 +129,11 @@ Use this for visualising diff scores.""",
    args = parser.parse_args()
    df = pd.read_csv(args.csv_report)

    # filter out missing format/category values
    mask_format_missing = df["format"].isna()
    mask_category_missing = df["category"].isna()
    df = df[~mask_format_missing | ~mask_category_missing]

    bins_for_measures = BINS_FOR_MEASURES
    if args.no_bins:
        bins_for_measures = {}
+34 −11
Original line number Diff line number Diff line
@@ -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__()
@@ -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 = {}
@@ -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."
    )


@@ -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)