Commit 82ff7683 authored by Jan Kiene's avatar Jan Kiene
Browse files

fix comparison per file type and reporting

parent 1fde59a2
Loading
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -128,34 +128,40 @@ def test_26252(test_tag, encoder_path, decoder_path, renderer_path, isar_post_re
        subprocess.run([isar_post_renderer_path] + isar_post_rend_opts.split()[1:], check = True)

    diff_opts = replace_paths(diff_opts, testv_path, ref_path, cut_path)
    result = True

    suffix = ""
    diff_in = {".wav": False, ".met": False, ".csv": False}

    for cmd in diff_opts.split(';'):
        file_a = Path(cmd.split()[1])
        file_b = Path(cmd.split()[2])

        suffix = file_a.suffix
        assert suffix == file_b.suffix
        assert suffix in diff_in

        # for .csv ISM metadata files, do text-based comparison to not take line endings into account
        # everything else (.wav output files and MASA metadata files) is compared as binary files
        if Path(file_a).suffix == ".csv":
            with open(file_a, "r") as f_a:
                with open(file_b, "r") as f_b:
                    a_content = f_a.read()
                    b_content = f_b.read()
                    result = result and a_content == b_content

                    files_equal = a_content == b_content
        else:
            result = result and filecmp.cmp(file_a, file_b)
            files_equal = filecmp.cmp(file_a, file_b)

    if not result:
        if not files_equal:
            diff_in[suffix] = True

    if any(diff_in.values()):
        result_str = "Output differs in: "
        if suffix == ".csv":
        if diff_in[".csv"]:
            result_str += "object metadata "
        elif suffix == ".met":
        if diff_in[".met"]:
            result_str += "MASA metadata "
        elif suffix == ".wav":
        if diff_in[".wav"]:
            result_str += "waveform"
        else:
            assert False, f"Either no diff commands were found or the output files had an incorrect suffix. \ncmd: {diff_opts}"

        pytest.fail(result_str)