Files
make-cad/test/test_error_harness.py
T
NiJingzhe acc513d97b feat(errors): sweep/loft family diagnosis + English error-text sweep
P1 family 5 (sweep/loft): open-wire profiles now report the measured gap
(endpoint pair, distance, chain count) instead of a bare closedness
complaint - extrude_rsolid and make_face_from_wire_rface raise points
rewired through diagnose_open_wire (endpoint-pairing union-find, tolerance
scaled to wire extent; a lone segment reports its own length as the gap).
Kernel loft failures (loft_rsolid + loft_rshell, which report a wordless
'build did not complete') get a section compatibility verdict: coincident
consecutive stations (the empirically dominant cause), edge-count
mismatch, open section wires, and backtracking station order, with a
per-station S1..Sn inventory (edges/closure/planarity/centroid).

Wire evidence renders through a new 2D plan schematic
(render_wire_plan_evidence): the 3D VTK pipeline cannot mesh bare wires
('no renderable triangles'), so edges are parameter-sampled to
polylines, PCA-projected onto the best-fit plane, and drawn matplotlib -
same ink/palette language as the sketch diagnostics. Open-wire evidence
highlights the two gap-end edges and pins P1/P2; loft evidence
highlights the implicated stations.

Family 6 audit conclusion recorded in the review table: knot uniqueness
and trim bounds are already guarded, offset_wires was never implemented;
the one real gap (bspline fit silent garbage exit) needs curvature
probes and stays queued as mechanism-E work.

Error-language contract regression: test_error_harness pins English-only
error text (CJK masked in technical details) - all Chinese repair lines
from this branch's earlier rounds are translated to English, figure text
stays ASCII (DejaVu has no CJK glyphs), each new family test pins a
CJK-free assertion, and the legacy extrude guidance test now asserts the
structured gap contract (gap == 1.0 for a single open segment).

Full suite 1858 passed, 5 skipped; ty clean on changed modules.
2026-09-12 18:47:18 +08:00

85 lines
3.1 KiB
Python

from __future__ import annotations
import subprocess
import sys
import unittest
import simplecadapi as scad
class TestErrorHarness(unittest.TestCase):
def test_simplecad_error_is_public(self):
self.assertTrue(hasattr(scad, "SimpleCADError"))
def test_make_box_raises_llm_friendly_english_error(self):
with self.assertRaises(scad.SimpleCADError) as ctx:
scad.make_box_rsolid(0.0, 1.0, 1.0)
message = str(ctx.exception)
self.assertIn("Operation: make_box_rsolid", message)
self.assertIn("Signature: make_box_rsolid(", message)
self.assertIn(
"Documentation: For full usage details, run help(simplecadapi.make_box_rsolid).",
message,
)
self.assertIn("What happened:", message)
self.assertIn("Possible causes:", message)
self.assertIn("How to fix:", message)
self.assertIn("Technical details:", message)
self.assertIn("Failed to create a box solid.", message)
self.assertIn("Use width, height, and depth values greater than zero.", message)
self.assertNotRegex(message, r"[\u3400-\u9fff\uf900-\ufaff]")
def test_extrude_raises_actionable_closed_wire_guidance(self):
wire = scad.make_segment_rwire((0.0, 0.0, 0.0), (1.0, 0.0, 0.0))
with self.assertRaises(scad.SimpleCADError) as ctx:
scad.extrude_rsolid(wire, (0.0, 0.0, 1.0), 2.0)
message = str(ctx.exception)
self.assertIn("Operation: extrude_rsolid", message)
self.assertIn("Signature: extrude_rsolid(", message)
# Structured diagnosis: the measured gap (a single open segment
# reports the full segment length as its own gap) supersedes the
# generic "make sure the wire is closed" advice.
guidance = ctx.exception.guidance
measurements = {m.name: m.value for m in guidance.measurements}
self.assertAlmostEqual(measurements["gap"], 1.0)
self.assertIn("not closed", guidance.what_happened)
self.assertNotRegex(message, r"[\u3400-\u9fff\uf900-\ufaff]")
def test_import_graph_json_reports_signature_and_help(self):
with self.assertRaises(scad.SimpleCADError) as ctx:
scad.import_graph_json('{"schema_version":"1.0","nodes":[],"edges":[]}')
message = str(ctx.exception)
self.assertIn("Operation: import_graph_json", message)
self.assertIn("Signature: import_graph_json(", message)
self.assertIn(
"Documentation: For full usage details, run help(simplecadapi.import_graph_json).",
message,
)
def test_vendor_swig_deprecation_warnings_are_suppressed_on_import(self):
result = subprocess.run(
[
sys.executable,
"-W",
"default",
"-c",
"import simplecadapi",
],
capture_output=True,
text=True,
check=True,
)
stderr = result.stderr
self.assertNotIn("SwigPyPacked", stderr)
self.assertNotIn("SwigPyObject", stderr)
self.assertNotIn("swigvarlink", stderr)
if __name__ == "__main__":
unittest.main()