Prepare SPHLite 0.2.0 development baseline
This commit is contained in:
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
|
||||
FORTRAN_FILE_MAX_LINES = 700
|
||||
C_FILE_MAX_LINES = 500
|
||||
PYTHON_FILE_MAX_LINES = 500
|
||||
FORTRAN_PROCEDURE_MAX_LINES = 140
|
||||
|
||||
|
||||
@@ -34,7 +35,7 @@ def source_files(root: Path) -> list[Path]:
|
||||
continue
|
||||
if rel_path.parts and rel_path.parts[0].startswith("build"):
|
||||
continue
|
||||
if path.suffix.lower() in {".f90", ".c", ".h", ".hpp"}:
|
||||
if path.suffix.lower() in {".f90", ".c", ".cpp", ".h", ".hpp", ".py"}:
|
||||
result.append(path)
|
||||
return sorted(result)
|
||||
|
||||
@@ -49,8 +50,10 @@ def check_file_lines(root: Path, path: Path, exceptions: set[str], errors: list[
|
||||
suffix = path.suffix.lower()
|
||||
if suffix in {".f90"}:
|
||||
limit = FORTRAN_FILE_MAX_LINES
|
||||
elif suffix in {".c", ".h", ".hpp"}:
|
||||
elif suffix in {".c", ".cpp", ".h", ".hpp"}:
|
||||
limit = C_FILE_MAX_LINES
|
||||
elif suffix == ".py":
|
||||
limit = PYTHON_FILE_MAX_LINES
|
||||
else:
|
||||
return
|
||||
if len(lines) > limit and rel not in exceptions:
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_command(args: list[str], expect_ok: bool = True) -> subprocess.CompletedProcess[str]:
|
||||
result = subprocess.run(args, text=True, capture_output=True)
|
||||
if expect_ok and result.returncode != 0:
|
||||
raise AssertionError(result.stderr or result.stdout)
|
||||
if not expect_ok and result.returncode == 0:
|
||||
raise AssertionError("command unexpectedly succeeded")
|
||||
return result
|
||||
|
||||
|
||||
def require_field(output: str, field: str) -> None:
|
||||
if f"{field}:" not in output:
|
||||
raise AssertionError(f"missing CLI field {field}")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--exe", required=True)
|
||||
parser.add_argument("--input", required=True)
|
||||
parser.add_argument("--bad-input", required=True)
|
||||
parser.add_argument("--output-dir", required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
exe = str(Path(args.exe))
|
||||
model = str(Path(args.input))
|
||||
bad_model = str(Path(args.bad_input))
|
||||
output_dir = str(Path(args.output_dir))
|
||||
|
||||
version = run_command([exe, "--version"])
|
||||
require_field(version.stdout, "version")
|
||||
if "0.1.1" not in version.stdout:
|
||||
raise AssertionError("CLI version mismatch")
|
||||
|
||||
inspect = run_command([exe, model])
|
||||
for field in ("version", "input", "mode", "particles", "warnings", "time", "step", "status"):
|
||||
require_field(inspect.stdout, field)
|
||||
if "mode: inspect" not in inspect.stdout:
|
||||
raise AssertionError("inspect mode not reported")
|
||||
|
||||
check = run_command([exe, model, "--check"])
|
||||
if "mode: check" not in check.stdout:
|
||||
raise AssertionError("check mode not reported")
|
||||
|
||||
run = run_command([exe, model, "--run", "--output", output_dir])
|
||||
if "mode: run" not in run.stdout:
|
||||
raise AssertionError("run mode not reported")
|
||||
if "step: 1" not in run.stdout:
|
||||
raise AssertionError("run mode did not advance")
|
||||
|
||||
bad = run_command([exe, bad_model, "--check"], expect_ok=False)
|
||||
require_field(bad.stderr, "error_code")
|
||||
require_field(bad.stderr, "error_message")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -14,9 +14,12 @@ def main() -> int:
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(root / "Python"))
|
||||
|
||||
from sphlite_debug import SPHLite
|
||||
from sphlite_debug import PHASE_SOLID, STATUS_ACTIVE, SPHLite, SPHLiteError
|
||||
|
||||
solver = SPHLite(args.library)
|
||||
if PHASE_SOLID != 4 or STATUS_ACTIVE != 0:
|
||||
raise AssertionError("Python constants are not locked")
|
||||
|
||||
solver.initialize()
|
||||
try:
|
||||
solver.read_inp(args.input)
|
||||
@@ -24,9 +27,29 @@ def main() -> int:
|
||||
count = solver.particle_count()
|
||||
if count != 4:
|
||||
raise AssertionError(f"expected 4 particles, got {count}")
|
||||
state = solver.particle_state()
|
||||
if state["phase"][0] != PHASE_SOLID:
|
||||
raise AssertionError("unexpected particle phase")
|
||||
solver.set_output_directory(root / "build-codex-unix")
|
||||
solver.write_output(0, 0.0)
|
||||
restart = root / "build-codex-unix" / "python_restart.tmp"
|
||||
solver.write_restart(restart)
|
||||
solver.read_restart(restart)
|
||||
solver.run_explicit()
|
||||
finally:
|
||||
solver.finalize()
|
||||
|
||||
missing = SPHLite(args.library)
|
||||
missing.initialize()
|
||||
try:
|
||||
try:
|
||||
missing.read_inp(root / "tests" / "data" / "does_not_exist.inp")
|
||||
except SPHLiteError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("missing input did not raise")
|
||||
finally:
|
||||
missing.finalize()
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user