Commit 6ff9e500 authored by norvell's avatar norvell
Browse files

Fix scripts/parse_commands.py for pytest-html v3

parent 302a5c5b
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -38,6 +38,36 @@ if __name__ == '__main__':
                    cmds_dec.extend(re.findall(r"DUT decoder command:\\n\\t(.*?)\\n", line))
                    cmds_rend.extend(re.findall(r"Running command\\n(.*?)\\n", line))

    # If pytest-html < v4 is used, the parsing will fail and render empty lists. This is a work-around in case that happens.
    if all(not x for x in [cmds_enc, cmds_dec, cmds_rend]):
        for html_report in input:
            with open(html_report,'r') as infile:
                enc_cmd = False
                dec_cmd = False
                rend_cmd = False
                for line in infile.readlines():
                    if enc_cmd:
                        cmds_enc.append(line)
                        enc_cmd = False
                    elif dec_cmd:
                        cmds_dec.append(line)
                        dec_cmd = False
                    elif rend_cmd:
                        cmds_rend.append(line)
                        rend_cmd = False
                    else:
                        if "DUT encoder command" in line:
                            enc_cmd = True
                        elif "DUT decoder command" in line:
                            dec_cmd = True
                        elif "Running command" in line:
                            rend_cmd = True

    # Sort lists to keep deterministic order between runs
    cmds_enc.sort()
    cmds_dec.sort()
    cmds_rend.sort()

    with open(txt_file.replace('.','_enc.'),'w', newline='\n') as outfile:
        with open('scripts/enc_header.txt','r') as header:
            outfile.write(header.read())