Import CAD projects and cad-router v1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROUTE_PATH = Path(__file__).resolve().parents[4] / "skills" / "cad-router" / "scripts" / "route.py"
|
||||
SPEC = importlib.util.spec_from_file_location("cad_router_route", ROUTE_PATH)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
route_module = importlib.util.module_from_spec(SPEC)
|
||||
sys.modules[SPEC.name] = route_module
|
||||
SPEC.loader.exec_module(route_module)
|
||||
|
||||
|
||||
class CadRouterTests(unittest.TestCase):
|
||||
def parse(self, *args: str):
|
||||
return route_module.build_parser().parse_args(list(args))
|
||||
|
||||
def test_routes_gear_to_simplecadapi(self) -> None:
|
||||
result = route_module.route(self.parse("生成一个模数 2 的人字齿轮", "--output", "step"))
|
||||
self.assertEqual("simplecadapi", result["selected_backend"])
|
||||
|
||||
def test_routes_connecting_rod_to_build123d(self) -> None:
|
||||
result = route_module.route(
|
||||
self.parse("生成中心距 120mm 的发动机连杆", "--output", "step", "--manufacturing", "machining")
|
||||
)
|
||||
self.assertEqual("build123d", result["selected_backend"])
|
||||
|
||||
def test_routes_printable_vase_to_cadam(self) -> None:
|
||||
result = route_module.route(
|
||||
self.parse("生成一个带蜂窝纹理的可调参数 3D 打印花瓶", "--output", "stl", "--browser-controls")
|
||||
)
|
||||
self.assertEqual("cadam", result["selected_backend"])
|
||||
self.assertEqual("CADAM", result["project"])
|
||||
self.assertEqual("scripts/cadam_compile.mjs", result["adapter"])
|
||||
|
||||
def test_existing_step_stays_step_first(self) -> None:
|
||||
result = route_module.route(self.parse("修改现有零件的孔径", "--existing-model", "--output", "step"))
|
||||
self.assertEqual("build123d", result["selected_backend"])
|
||||
|
||||
def test_scad_output_is_hard_signal(self) -> None:
|
||||
result = route_module.route(self.parse("做一个参数化旋钮", "--output", "scad"))
|
||||
self.assertEqual("cadam", result["selected_backend"])
|
||||
|
||||
def test_every_route_applies_caddesigner_ecip_and_reports_all_project_roles(self) -> None:
|
||||
result = route_module.route(self.parse("生成一个 40mm 法兰", "--output", "step"))
|
||||
self.assertIn("caddesigner_ecip", result["workflow_profiles"])
|
||||
self.assertEqual(
|
||||
{"text-to-cad", "SimpleCADAPI", "CADAM", "CADDesigner-Code"},
|
||||
set(result["project_contributions"]),
|
||||
)
|
||||
|
||||
def test_cadam_probe_finds_sibling_runtime(self) -> None:
|
||||
expected_root = Path(__file__).resolve().parents[5] / "CADAM"
|
||||
if expected_root.is_dir():
|
||||
self.assertTrue(route_module.cadam_runtime_available(expected_root))
|
||||
|
||||
def test_explicit_override_is_respected(self) -> None:
|
||||
result = route_module.route(self.parse("生成一个齿轮", "--backend", "build123d"))
|
||||
self.assertEqual("build123d", result["selected_backend"])
|
||||
selected = next(item for item in result["backend_scores"] if item["backend"] == "build123d")
|
||||
self.assertIn("explicit backend override", selected["reasons"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user