Peano
Loading...
Searching...
No Matches
test_merge.py
Go to the documentation of this file.
1import numpy as np
2import pytest
3
4from tarch.plotter.api import merge
5from tarch.plotter.api.input.PatchFileParser import PatchFileParser
6
7from test_binary_patch_file import write_file, values_of_patch
8
9
10def write_meta_file(path, files_per_snapshot):
11 lines = ["# ", "# Peano patch file ", "# Version 0.2 ", "# ", "format ASCII", ""]
12 for index, files in enumerate(files_per_snapshot):
13 lines += ["begin dataset", f" timestamp {float(index):e}", ""]
14 lines += [f' include "{name}"' for name in files]
15 lines += ["end dataset", ""]
16 path.write_text("\n".join(lines) + "\n")
17
18
19@pytest.mark.parametrize("binary", [False, True])
20def test_merge_two_partial_files_of_one_snapshot(tmp_path, monkeypatch, binary):
21 monkeypatch.chdir(tmp_path)
22 # Two partial files with two patches each; the second pair uses ids 2 and 3
23 write_file(tmp_path / "a.peano-patch-file", binary, patches=2, evil=binary)
24 write_file(tmp_path / "b.peano-patch-file", binary, patches=2, evil=binary)
26 tmp_path / "meta.peano-patch-file",
27 [["a.peano-patch-file", "b.peano-patch-file"]],
28 )
29
30 start, end = 0, 0
31 merge.read_meta_file("meta.peano-patch-file", start, end)
32
33 merged = PatchFileParser(
34 str(tmp_path / "merged_patch_file_0.peano-patch-file"), "Q", 0
35 )
36 merged.parse_file()
37 assert merged.parsed
38 assert merged.file_format == ("Binary" if binary else "ASCII")
39
40 patches = merged.unknown_attributes["Q"].cell_data
41 assert len(patches) == 4
42 for index, patch in enumerate(patches):
43 expected = values_of_patch(index % 2, evil=binary)
44 assert patch.values.tobytes() == expected.tobytes()
45
46 meta = (tmp_path / "merged_meta_file.peano-patch-file").read_text()
47 assert 'include "merged_patch_file_0.peano-patch-file"' in meta
write_meta_file(path, files_per_snapshot)
Definition test_merge.py:10
test_merge_two_partial_files_of_one_snapshot(tmp_path, monkeypatch, binary)
Definition test_merge.py:20