Files
SPHLite/tools/testing/test_python_debug.py
T

58 lines
1.6 KiB
Python
Raw Normal View History

2026-07-02 18:47:38 +08:00
from __future__ import annotations
import argparse
import sys
from pathlib import Path
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--library", required=True)
parser.add_argument("--input", required=True)
args = parser.parse_args()
root = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(root / "Python"))
2026-07-02 19:50:44 +08:00
from sphlite_debug import PHASE_SOLID, STATUS_ACTIVE, SPHLite, SPHLiteError
2026-07-02 18:47:38 +08:00
solver = SPHLite(args.library)
2026-07-02 19:50:44 +08:00
if PHASE_SOLID != 4 or STATUS_ACTIVE != 0:
raise AssertionError("Python constants are not locked")
2026-07-02 18:47:38 +08:00
solver.initialize()
try:
solver.read_inp(args.input)
solver.build_model()
count = solver.particle_count()
if count != 4:
raise AssertionError(f"expected 4 particles, got {count}")
2026-07-02 19:50:44 +08:00
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)
2026-07-02 18:47:38 +08:00
solver.run_explicit()
finally:
solver.finalize()
2026-07-02 19:50:44 +08:00
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()
2026-07-02 18:47:38 +08:00
return 0
if __name__ == "__main__":
raise SystemExit(main())