237702c7a8
- rename every numbered example (04/08/10/11/7ep scripts, 12/16/20/21 dirs) to clean names; each example now writes artifacts to its own out/ folder - examples/README rewritten as a category index (part / assembly / reverse engineering / FEM); stale run_examples.py reference removed - flange_plate gains the quickstart FTC part (model.py + external verify.py + README); u_link/ap242/flange demo builders read the new asset paths - ap242_gmsh_volume_mesh gains render_views.py for the demo gallery fix(artifacts): round-trip-stable geometry fingerprint bounds AddOptimal bounds wobble by one shape-tolerance quantum between a fresh shape and the same shape read back from BRep bytes, so definitions sitting on a quantization cell edge failed every package re-validation. Quantize bounds at a fixed 1e-4 mm grid, far coarser than the wobble; full suite green (1503 passed). Stored packages captured before this change must be recaptured.
98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
"""Structural checks for the example model/session contract."""
|
|
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
import simplecadapi as scad
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
EXAMPLES = ROOT / "examples"
|
|
|
|
|
|
def _source_files() -> tuple[Path, ...]:
|
|
return tuple(
|
|
path
|
|
for path in EXAMPLES.rglob("*.py")
|
|
if "out" not in path.relative_to(EXAMPLES).parts
|
|
)
|
|
|
|
|
|
|
|
|
|
class TestExampleModelContract(unittest.TestCase):
|
|
def test_hydraulic_rod_assembly_output_dir_is_anchored_to_the_example_file(self):
|
|
path = EXAMPLES / "hydraulic_rod_assembly" / "model.py"
|
|
spec = importlib.util.spec_from_file_location(
|
|
"hydraulic_rod_assembly_path_contract", path
|
|
)
|
|
self.assertIsNotNone(spec)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
|
|
self.assertTrue(module.OUT_DIR.is_absolute())
|
|
self.assertEqual(
|
|
module.OUT_DIR,
|
|
EXAMPLES / "hydraulic_rod_assembly" / "out",
|
|
)
|
|
|
|
|
|
def test_examples_do_not_use_removed_decorator_api(self):
|
|
for path in _source_files():
|
|
source = path.read_text(encoding="utf-8")
|
|
self.assertNotIn("@scad.model", source, path)
|
|
self.assertNotIn("scad.requires_session", source, path)
|
|
self.assertNotIn("scad.capture_result", source, path)
|
|
|
|
def test_bldc_bearing_decorative_balls_are_part_of_outer_ring(self):
|
|
example_dir = EXAMPLES / "integrated_bldc_joint_actuator"
|
|
sys.path.insert(0, str(example_dir))
|
|
try:
|
|
path = example_dir / "bearings.py"
|
|
spec = importlib.util.spec_from_file_location(
|
|
"bldc_bearings_contract", path
|
|
)
|
|
self.assertIsNotNone(spec)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
from dimensions import BearingSpec
|
|
|
|
bearing_spec = BearingSpec(3.0, 6.0, 3.0, 0.7, 8)
|
|
with scad.GraphSession():
|
|
material = scad.make_material_rmaterial(
|
|
"bearing_contract_steel",
|
|
density=7.85e-6,
|
|
density_unit="kg/mm^3",
|
|
)
|
|
bearing = module.make_main_bearing_rassembly(
|
|
bearing_id="bearing_contract",
|
|
spec=bearing_spec,
|
|
material=material,
|
|
)
|
|
solved = scad.solve_assembly_constraints_rassembly(
|
|
scad.ground_component_rassembly(bearing, "outer_ring")
|
|
)
|
|
report = scad.inspect_assembly_constraints_rconstraintreport(solved)
|
|
finally:
|
|
sys.path.remove(str(example_dir))
|
|
|
|
self.assertEqual(bearing.component_ids(), ("outer_ring", "inner_ring"))
|
|
self.assertEqual(bearing.constraint_ids(), ("inner_outer_revolute",))
|
|
self.assertEqual(report.unsolved_component_ids, ())
|
|
outer = bearing.get_component("outer_ring").item.body
|
|
outer_meta = bearing.get_metadata("std.bearing.ball_bearing")
|
|
self.assertTrue(outer_meta["rolling_elements_fused"])
|
|
self.assertEqual(outer_meta["rolling_element_fuse_mode"], "outer_ring_union")
|
|
self.assertGreater(outer.get_volume(), 0.0)
|
|
self.assertIn(
|
|
"role.rolling_elements_fused_into_outer_ring", scad.list_tags(outer)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|