Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tools/test_verify_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import tempfile
import unittest
from pathlib import Path

from verify_lib import find_last_output


class FindLastOutputTest(unittest.TestCase):
def test_combines_csv_files_without_cat(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
for rank in (0, 1):
for step in (1, 2):
path = root / f"output-2D-{rank}-0000{step}.csv"
path.write_text(f"rank{rank}\n")

output, combined = find_last_output(dir=directory)

self.assertTrue(combined)
self.assertEqual(Path(output).read_text(), "rank0\nrank1\n")


if __name__ == "__main__":
unittest.main()
8 changes: 5 additions & 3 deletions tools/verify_lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import glob
import os
import subprocess
import shutil
from collections.abc import Callable
from importlib import util as imputil
from typing import Any
Expand Down Expand Up @@ -216,8 +216,10 @@ def find_last_output(

# Combine the files
new_file = combine[-1].replace(f"D-{mm}-", f"D-{mm + 1}-")
with open(new_file, "w") as fwrite:
subprocess.run(["cat"] + combine, stdout=fwrite)
with open(new_file, "wb") as fwrite:
for file in combine:
with open(file, "rb") as fread:
shutil.copyfileobj(fread, fwrite, length=1024 * 1024)
return new_file, True


Expand Down
Loading