Files
pythonocc-step-editor/scripts/verify_relation_formula_rules.py
T
nikelaluo 4e7877e05c feat: 接入 SCDM 优先编辑闭环并支持阵列局部间距
接入 SCDM probe/edit/cache/校验链路,增强孔组、阵列、关系式和参数表交互。

支持阵列相邻段间距、移动意图切换、结果回滚校验,并补充对应回归脚本。
2026-08-19 18:02:47 +08:00

60 lines
1.8 KiB
Python

from __future__ import annotations
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from step_editor.relation_formulas import ( # noqa: E402
RelationFormulaError,
parse_relation_formula,
validate_relation_formula_graph,
)
def _parse_many(texts: list[str]):
return [parse_relation_formula(text) for text in texts]
def _assert_ok(texts: list[str]) -> None:
validate_relation_formula_graph(_parse_many(texts))
def _assert_fails(texts: list[str], expected_fragment: str) -> None:
try:
validate_relation_formula_graph(_parse_many(texts))
except RelationFormulaError as exc:
message = str(exc)
if expected_fragment not in message:
raise AssertionError(f"expected {expected_fragment!r} in error message, got {message!r}") from exc
return
raise AssertionError(f"expected relation formulas to fail: {texts!r}")
def main() -> int:
_assert_ok(["Face87.直径 = Face87.半径 + 0.1"])
_assert_ok(["Face87.位置 = Face85.位置 + (0, 0, -3.5)"])
_assert_ok(["Face85.直径 = Face87.半径", "Face11.直径 = Face85.半径"])
_assert_fails(["Face87.直径 = Face87.直径 + 0.1"], "不能引用自身")
_assert_fails(["Face85.直径 = Face87.半径", "Face85.直径 = Face11.半径"], "同一目标参数")
_assert_fails(["Face85.直径 = Face87.直径", "Face87.直径 = Face85.直径"], "循环依赖")
_assert_fails(
[
"Face1.位置 = Face2.位置",
"Face2.位置 = Face3.位置",
"Face3.位置 = Face1.位置",
],
"循环依赖",
)
print("relation formula rules ok")
return 0
if __name__ == "__main__":
raise SystemExit(main())