MCPcopy Index your code
hub / github.com/CadQuery/cadquery / test_materials

Function test_materials

tests/test_assembly.py:1692–1735  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1690
1691
1692def test_materials():
1693 # Test a default material not attached to an assembly
1694 mat_0 = cq.Material()
1695 assert mat_0.name == "Default"
1696
1697 # Simple objects to be added to the assembly with the material
1698 wp_1 = cq.Workplane().box(10, 10, 10)
1699 wp_2 = cq.Workplane().box(5, 5, 5)
1700 wp_3 = cq.Workplane().box(2.5, 2.5, 2.5)
1701
1702 # Add the object to the assembly with the material
1703 assy = cq.Assembly()
1704
1705 # Test with a default material
1706 mat_1 = cq.Material()
1707 assy.add(wp_1, material=mat_1)
1708 assert assy.children[0].material.name == "Default"
1709 assert assy.children[0].material.description == ""
1710 assert assy.children[0].material.density == 7.85
1711 assert assy.children[0].material.densityUnit == "g/cm^3"
1712
1713 # Test with a user-defined material when passing properties in constructor
1714 mat_2 = cq.Material(
1715 "test", description="Test material", density=1.0, densityUnit="lb/in^3"
1716 )
1717 assy.add(wp_2, material=mat_2)
1718 assert assy.children[1].material.name == "test"
1719 assert assy.children[1].material.description == "Test material"
1720 assert assy.children[1].material.density == 1.0
1721 assert assy.children[1].material.densityUnit == "lb/in^3"
1722
1723 # The visualization material is left for later expansion
1724 assert assy.children[1].material.wrapped_vis.IsEmpty()
1725
1726 # Test the ability to convert a material to a tuple
1727 assert mat_2.toTuple() == ("test", "Test material", 1.0, "lb/in^3")
1728
1729 # Test the ability to have a material
1730 assert mat_2.__hash__() == hash(("test", "Test material", 1.0, "lb/in^3"))
1731
1732 # Test the equality operator with material
1733 assert mat_2 == cq.Material(
1734 "test", description="Test material", density=1.0, densityUnit="lb/in^3"
1735 )
1736
1737
1738@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

addMethod · 0.95
toTupleMethod · 0.95
__hash__Method · 0.95
boxMethod · 0.80

Tested by

no test coverage detected