""" Unit tests for tooling """ import unittest import cadquery as Cq from nhf.build import Model, target import nhf.checks import nhf.utils # Color presets for testing purposes color_parent = Cq.Color(0.7, 0.7, 0.5, 0.5) color_child = Cq.Color(0.5, 0.7, 0.7, 0.5) def makeSphere(r: float) -> Cq.Solid: """ Makes a full sphere. The default function makes a hemisphere """ return Cq.Solid.makeSphere(r, angleDegrees1=-90) class BuildScaffold(Model): def __init__(self): super().__init__(name="scaffold") @target(name="obj1") def o1(self): return Cq.Solid.makeBox(10, 10, 10) def o2(self): return Cq.Solid.makeCylinder(10, 20) class TestBuild(unittest.TestCase): def test_build_scaffold(self): s = BuildScaffold() names = ["obj1"] self.assertEqual(s.target_names, names) self.assertEqual(s.check_all(), len(names)) class TestChecks(unittest.TestCase): def intersect_test_case(self, offset): assembly = ( Cq.Assembly() .add(Cq.Solid.makeBox(10, 10, 10), name="c1", loc=Cq.Location((0, 0, 0))) .add(Cq.Solid.makeBox(10, 10, 10), name="c2", loc=Cq.Location((0, 0, offset))) ) coll = nhf.checks.pairwise_intersection(assembly) if -10 < offset and offset < 10: self.assertEqual(len(coll), 1) else: self.assertEqual(coll, []) def test_intersect(self): for offset in [9, 10, 11, -10]: with self.subTest(offset=offset): self.intersect_test_case(offset) class TestUtils(unittest.TestCase): def test_tag_point(self): """ A board with 3 holes of unequal sizes. Each hole is marked """ p4x, p4y = 5, 5 p3x, p3y = 0, 0 p2x, p2y = -5, 0 board = ( Cq.Workplane('XY') .box(15, 15, 5) .faces("