MCPcopy
hub / github.com/CadQuery/cadquery / test_assembly_remove_subassy

Function test_assembly_remove_subassy

tests/test_assembly.py:2445–2484  ·  view source on GitHub ↗

Tests the ability to remove a subassembly from an assembly.

()

Source from the content-addressed store, hash-verified

2443
2444
2445def test_assembly_remove_subassy():
2446 """
2447 Tests the ability to remove a subassembly from an assembly.
2448 """
2449
2450 # Create the top-level assembly
2451 assy = cq.Assembly()
2452 assy.add(box(1, 1, 1), name="loplevel_part1")
2453
2454 # Create the subassembly
2455 subassy = cq.Assembly()
2456 subassy.add(box(1, 1, 1), name="part1")
2457 subassy.add(box(2, 2, 2), name="part2", loc=cq.Location(5.0, 5.0, 5.0))
2458
2459 # Add the subassembly to the top-level assembly
2460 assy.add(subassy, name="subassy")
2461
2462 # Make sure we have the 1 top-level part and the subassembly
2463 assert len(assy.children) == 2
2464 assert len(assy.objects) == 5
2465
2466 # Remove the subassembly
2467 assy.remove("subassy")
2468
2469 # Make sure we have the correct number of children (1 part)
2470 assert len(assy.children) == 1
2471 assert len(assy.objects) == 2
2472
2473 # Recreate the assembly with a nested subassembly
2474 assy = cq.Assembly()
2475 assy.add(box(1, 1, 1), name="loplevel_part1")
2476 subassy = cq.Assembly()
2477 subassy.add(box(1, 1, 1), name="part1")
2478 subassy.add(box(2, 2, 2), name="part2", loc=cq.Location(2.0, 2.0, 2.0))
2479 assy.add(subassy, name="subassy")
2480
2481 # Try to remove a part from a subassembly by using the path string
2482 assert len(assy.children[1].children) == 2
2483 assy.remove("subassy/part2")
2484 assert len(assy.children[1].children) == 1
2485
2486
2487def test_remove_without_parent():

Callers

nothing calls this directly

Calls 3

addMethod · 0.95
removeMethod · 0.95
boxFunction · 0.85

Tested by

no test coverage detected