This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check femlite CLI output-directory success and failure boundaries."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def require(condition: bool, message: str) -> None:
|
||||
if not condition:
|
||||
raise AssertionError(message)
|
||||
|
||||
|
||||
def run_command(command: list[str], cwd: Path) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
command,
|
||||
cwd=cwd,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
if len(argv) != 4:
|
||||
print(
|
||||
"usage: check_cli_output_dir.py <repo-root> <femlite-exe> <build-dir>",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
|
||||
repo_root = Path(argv[1]).resolve()
|
||||
femlite_exe = Path(argv[2]).resolve()
|
||||
build_dir = Path(argv[3]).resolve()
|
||||
input_file = repo_root / "tests" / "data" / "c3d4_static_pull.inp"
|
||||
|
||||
out_dir = build_dir / "cli_output_dir_boundary" / "nested" / "static"
|
||||
if out_dir.parent.parent.exists():
|
||||
shutil.rmtree(out_dir.parent.parent)
|
||||
|
||||
ok = run_command(
|
||||
[
|
||||
str(femlite_exe),
|
||||
str(input_file),
|
||||
"--static-linear",
|
||||
"--output-dir",
|
||||
str(out_dir),
|
||||
"--output-interval",
|
||||
"1",
|
||||
],
|
||||
repo_root,
|
||||
)
|
||||
require(ok.returncode == 0, f"successful output-dir run failed:\n{ok.stdout}")
|
||||
require(out_dir.is_dir(), "CLI did not create nested output directory")
|
||||
require((out_dir / "history.csv").is_file(), "history.csv was not written")
|
||||
require(
|
||||
(out_dir / "result_00000001.vtk").is_file(),
|
||||
"VTK output was not written in the requested directory",
|
||||
)
|
||||
|
||||
bad_char = '"' if os.name == "nt" else "'"
|
||||
bad_dir = build_dir / f"cli_output_dir_bad{bad_char}path"
|
||||
bad = run_command(
|
||||
[str(femlite_exe), str(input_file), "--output-dir", str(bad_dir)],
|
||||
repo_root,
|
||||
)
|
||||
require(bad.returncode != 0, "invalid output-dir unexpectedly succeeded")
|
||||
require(
|
||||
"output directory path must not contain" in bad.stdout
|
||||
or "failed to create output directory" in bad.stdout,
|
||||
f"invalid output-dir did not report a stable error:\n{bad.stdout}",
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv))
|
||||
Reference in New Issue
Block a user