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

handle split comparison results in parse_xml_report.py

parent f227980b
Loading
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -6,6 +6,10 @@ from xml.etree import ElementTree
from collections import Counter


SPLIT_STRING = "_split"
WHOLE_STRING = "_whole"


class TestcaseParser(dict):
    def __init__(self, testcases: list):
        super().__init__()
@@ -38,6 +42,50 @@ class TestcaseParser(dict):
        properties = {
            p.get("name"): p.get("value") for p in testcase.findall(".//property")
        }

        ### handle split comparison results
        split_props = {k: v for k, v in properties.items() if SPLIT_STRING in k}
        whole_props = {k: v for k, v in properties.items() if WHOLE_STRING in k}

        if len(split_props) > 0 and len(whole_props) > 0:
            measures_from_split = set(
                [m.split(SPLIT_STRING)[0] for m in split_props.keys()]
            )
            measures_from_whole = set(
                [m.split(WHOLE_STRING)[0] for m in whole_props.keys()]
            )
            assert measures_from_split == measures_from_whole
            measures = measures_from_whole

            # collect existing split suffixes by evaluating one of the measures only
            m_tmp = measures.pop()
            splits = sorted(
                [
                    k.split(SPLIT_STRING)[-1]
                    for k in split_props.keys()
                    if k.startswith(m_tmp)
                ]
            )

            # record each split under a separate key
            # the dict per key has the same fulltestname and an additional key "split"
            # this way, the resulting DataFrame in the end can be split by testnames
            for s in splits:
                split_key = f"{fulltestname} - {s}"
                ret_split = {"testcase": fulltestname, "split": s}
                for m in measures:
                    ret_split.update({m: split_props[m + SPLIT_STRING + f"{s}"]})
                self[split_key] = ret_split

        # it can be the case that there are no splits defined in the pytest suite, e.g. for the renderer
        # then, there are only "_whole" values recorded where we only need to remove the suffix
        # this if also handles the split case - if there are splits, there was also a "_whole" comparison done
        if len(whole_props) > 0:
            properties = {
                k.replace(WHOLE_STRING, ""): v for k, v in whole_props.items()
            }
            properties["split"] = "whole"

        ret.update(properties)
        self[fulltestname] = ret