98 lines
3.6 KiB
Python
98 lines
3.6 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import subprocess
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
def run_command(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||
|
|
result = subprocess.run(args, text=True, capture_output=True)
|
||
|
|
if result.returncode != 0:
|
||
|
|
raise AssertionError(result.stderr or result.stdout)
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
def read_fields(output: str) -> dict[str, str]:
|
||
|
|
fields: dict[str, str] = {}
|
||
|
|
for line in output.splitlines():
|
||
|
|
if ":" in line:
|
||
|
|
name, value = line.split(":", 1)
|
||
|
|
fields[name.strip()] = value.strip()
|
||
|
|
return fields
|
||
|
|
|
||
|
|
|
||
|
|
def require_field(fields: dict[str, str], field: str) -> None:
|
||
|
|
if field not in fields:
|
||
|
|
raise AssertionError(f"missing coupling CLI field {field}")
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
parser = argparse.ArgumentParser()
|
||
|
|
parser.add_argument("--exe", required=True)
|
||
|
|
parser.add_argument("--input", required=True)
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
exe = str(Path(args.exe))
|
||
|
|
model = str(Path(args.input))
|
||
|
|
|
||
|
|
fields = read_fields(run_command([exe, model]).stdout)
|
||
|
|
for field in (
|
||
|
|
"coupling_regions",
|
||
|
|
"coupling_region_1_name",
|
||
|
|
"coupling_region_1_export_mode",
|
||
|
|
"coupling_region_1_import_mode",
|
||
|
|
"coupling_region_1_enabled",
|
||
|
|
"coupling_region_1_facets",
|
||
|
|
"coupling_region_2_name",
|
||
|
|
"coupling_region_2_export_mode",
|
||
|
|
"coupling_region_2_import_mode",
|
||
|
|
"coupling_region_2_particles",
|
||
|
|
"coupling_force_x",
|
||
|
|
"coupling_force_y",
|
||
|
|
"coupling_force_z",
|
||
|
|
"coupling_impulse_x",
|
||
|
|
"coupling_impulse_y",
|
||
|
|
"coupling_impulse_z",
|
||
|
|
"coupling_work",
|
||
|
|
"coupling_energy_exchange",
|
||
|
|
"coupling_nonfinite_imports",
|
||
|
|
"coupling_stale_loads",
|
||
|
|
):
|
||
|
|
require_field(fields, field)
|
||
|
|
|
||
|
|
if int(fields["coupling_regions"]) != 2:
|
||
|
|
raise AssertionError("coupling CLI region count mismatch")
|
||
|
|
if fields["coupling_region_1_name"] != "SHELL_FACETS":
|
||
|
|
raise AssertionError("coupling CLI region 1 name mismatch")
|
||
|
|
if int(fields["coupling_region_1_export_mode"]) != 2:
|
||
|
|
raise AssertionError("coupling CLI facet export mode mismatch")
|
||
|
|
if int(fields["coupling_region_1_import_mode"]) != 2:
|
||
|
|
raise AssertionError("coupling CLI facet import mode mismatch")
|
||
|
|
if int(fields["coupling_region_1_enabled"]) != 1:
|
||
|
|
raise AssertionError("coupling CLI enabled flag mismatch")
|
||
|
|
if int(fields["coupling_region_1_facets"]) != 3:
|
||
|
|
raise AssertionError("coupling CLI facet count mismatch")
|
||
|
|
if fields["coupling_region_2_name"] != "SHELL_BOTH":
|
||
|
|
raise AssertionError("coupling CLI region 2 name mismatch")
|
||
|
|
if int(fields["coupling_region_2_export_mode"]) != 3:
|
||
|
|
raise AssertionError("coupling CLI both export mode mismatch")
|
||
|
|
if int(fields["coupling_region_2_import_mode"]) != 1:
|
||
|
|
raise AssertionError("coupling CLI force import mode mismatch")
|
||
|
|
if int(fields["coupling_region_2_particles"]) != 3:
|
||
|
|
raise AssertionError("coupling CLI particle count mismatch")
|
||
|
|
if int(fields["coupling_nonfinite_imports"]) != 0:
|
||
|
|
raise AssertionError("coupling CLI nonfinite count mismatch")
|
||
|
|
if int(fields["coupling_stale_loads"]) != 0:
|
||
|
|
raise AssertionError("coupling CLI stale count mismatch")
|
||
|
|
|
||
|
|
check_fields = read_fields(run_command([exe, model, "--check"]).stdout)
|
||
|
|
if check_fields["mode"] != "check":
|
||
|
|
raise AssertionError("coupling CLI check mode mismatch")
|
||
|
|
if int(check_fields["coupling_regions"]) != 2:
|
||
|
|
raise AssertionError("coupling CLI check region count mismatch")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
raise SystemExit(main())
|