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

Function test_step_roundtrip_with_materials

tests/test_assembly.py:890–920  ·  view source on GitHub ↗

Tests to make sure that once materials have been exported to a file format such as STEP, the materials can be imported again.

(kind, tmpdir)

Source from the content-addressed store, hash-verified

888
889@pytest.mark.parametrize("kind", ["step", "xml", "xbf"])
890def test_step_roundtrip_with_materials(kind, tmpdir):
891 """
892 Tests to make sure that once materials have been exported to a file format
893 such as STEP, the materials can be imported again.
894 """
895
896 materials_assy = cq.Assembly()
897 materials_assy.add(
898 cq.Workplane().box(10, 10, 10),
899 name="cube_1",
900 material=cq.Material(name="copper"),
901 )
902
903 materials_path = f"roundtrip_materials.{kind}"
904
905 with chdir(tmpdir):
906 exportAssembly(materials_assy, materials_path)
907
908 # Read the contents as a step file as a string so we can check the outputs
909 with open(materials_path, "r") as f:
910 step_contents = f.read()
911
912 # Make sure that the face name string is present in the exported STEP contents
913 assert "copper" in step_contents
914
915 # Import the STEP file back in as an assembly
916 test_assy = cq.Assembly.importStep(materials_path)
917
918 # Make sure that the material was re-imported
919 assert test_assy.children[0].material is not None
920 assert test_assy.children[0].material.name == "copper"
921
922
923def test_step_export_assembly_unit_default(tmp_path_factory):

Callers

nothing calls this directly

Calls 4

addMethod · 0.95
exportAssemblyFunction · 0.90
boxMethod · 0.80
importStepMethod · 0.80

Tested by

no test coverage detected