tasks/libs/junit_upload.py
def split_junitxml(xml_path, codeowners, output_dir):
    """
    Split a junit XML into several according to the suite name and the codeowners.
    Returns a list with the owners of the written files.
    """
    tree = ET.parse(xml_path)
    output_xmls = {}
    for suite in tree.iter("testsuite"):
        path = suite.attrib["name"].replace(REPO_NAME_PREFIX, "", 1)

        # Dirs in CODEOWNERS might end with "/", but testsuite names in JUnit XML
        # don't, so for determining ownership we append "/" temporarily.
        owners = codeowners.of(path + "/")
        if not owners:
            raise KeyError(f"No code owner found for {path}")

        main_owner = owners[0][1][len(CODEOWNERS_ORG_PREFIX) :]
        try:
            xml = output_xmls[main_owner]
        except KeyError:
            xml = ET.ElementTree(ET.Element("testsuites"))
            output_xmls[main_owner] = xml
        xml.getroot().append(suite)

    for owner, xml in output_xmls.items():
        filepath = os.path.join(output_dir, owner + ".xml")
        xml.write(filepath, encoding="UTF-8", xml_declaration=True)

    return list(output_xmls)

    Split a junit XML into several according to the suite name and the codeowners.
    Returns a list with the owners of the written files.
    
Split a junit XML into several according to the suite name and the codeowners.
Returns a list with the owners of the written files.
Split a junit XML into several according to the suite name and the codeowners . Returns a list with the owners of the written files .
def split_junitxml(xml_path, codeowners, output_dir):
    tree = ET.parse(xml_path)
    output_xmls = {}
    for suite in tree.iter("testsuite"):
        path = suite.attrib["name"].replace(REPO_NAME_PREFIX, "", 1)
        owners = codeowners.of(path + "/")
        if not owners:
            raise KeyError(f"No code owner found for {path}")
        main_owner = owners[0][1][len(CODEOWNERS_ORG_PREFIX) :]
        try:
            xml = output_xmls[main_owner]
        except KeyError:
            xml = ET.ElementTree(ET.Element("testsuites"))
            output_xmls[main_owner] = xml
        xml.getroot().append(suite)
    for owner, xml in output_xmls.items():
        filepath = os.path.join(output_dir, owner + ".xml")
        xml.write(filepath, encoding="UTF-8", xml_declaration=True)
    return list(output_xmls)
def split_junitxml ( xml_path , codeowners , output_dir ) : tree = ET . parse ( xml_path ) output_xmls = { } for suite in tree . iter ( "testsuite" ) : path = suite . attrib [ "name" ] . replace ( REPO_NAME_PREFIX , "" , 1 ) owners = codeowners . of ( path + "/" ) if not owners : raise KeyError ( f"No code owner found for {path}" ) main_owner = owners [ 0 ] [ 1 ] [ len ( CODEOWNERS_ORG_PREFIX ) : ] try : xml = output_xmls [ main_owner ] except KeyError : xml = ET . ElementTree ( ET . Element ( "testsuites" ) ) output_xmls [ main_owner ] = xml xml . getroot ( ) . append ( suite ) for owner , xml in output_xmls . items ( ) : filepath = os . path . join ( output_dir , owner + ".xml" ) xml . write ( filepath , encoding = "UTF-8" , xml_declaration = True ) return list ( output_xmls )
Split a junit XML into several according to the suite name and the codeowners.
Split a junit XML into several according to the suite name and the codeowners .
"""
    Split a junit XML into several according to the suite name and the codeowners.
    Returns a list with the owners of the written files.
    """ # Dirs in CODEOWNERS might end with "/", but testsuite names in JUnit XML # don't, so for determining ownership we append "/" temporarily.
xml_path
codeowners
output_dir