Test if a file containing subshape information can be imported correctly.
(tmpdir, multi_subshape_assy, kind)
| 1108 | |
| 1109 | @pytest.mark.parametrize("kind", ["step", "xml", "xbf"]) |
| 1110 | def test_assembly_multi_subshape_import(tmpdir, multi_subshape_assy, kind): |
| 1111 | """ |
| 1112 | Test if a file containing subshape information can be imported correctly. |
| 1113 | """ |
| 1114 | |
| 1115 | assy_step_path = f"multi_subshape_assy.{kind}" |
| 1116 | |
| 1117 | with chdir(tmpdir): |
| 1118 | # Export the assembly |
| 1119 | multi_subshape_assy.export(assy_step_path) |
| 1120 | |
| 1121 | # Import the file back in |
| 1122 | imported_assy = cq.Assembly.load(assy_step_path) |
| 1123 | |
| 1124 | # Check that the top-level assembly name is correct |
| 1125 | assert imported_assy.name == "top_level" |
| 1126 | |
| 1127 | # Check the advanced face name for the first cube |
| 1128 | assert len(imported_assy.children[0]._subshape_names) == 1 |
| 1129 | assert ( |
| 1130 | list(imported_assy.children[0]._subshape_names.values())[0] == "cube_1_top_face" |
| 1131 | ) |
| 1132 | |
| 1133 | # Check the color for the first cube |
| 1134 | color = list(imported_assy.children[0]._subshape_colors.values())[0] |
| 1135 | assert Quantity_NameOfColor.Quantity_NOC_RED == color.wrapped.GetRGB().Name() |
| 1136 | |
| 1137 | # Check the layer info for the first cube |
| 1138 | layer_name = list(imported_assy.children[0]._subshape_layers.values())[0] |
| 1139 | assert layer_name == "cube_1_top_face" |
| 1140 | |
| 1141 | # Check the advanced face name for the second cube |
| 1142 | assert len(imported_assy.children[1]._subshape_names) == 1 |
| 1143 | assert ( |
| 1144 | list(imported_assy.children[1]._subshape_names.values())[0] |
| 1145 | == "cube_2_right_face" |
| 1146 | ) |
| 1147 | |
| 1148 | # Check the color |
| 1149 | color = list(imported_assy.children[1]._subshape_colors.values())[0] |
| 1150 | assert Quantity_NameOfColor.Quantity_NOC_RED == color.wrapped.GetRGB().Name() |
| 1151 | |
| 1152 | # Check the layer info |
| 1153 | layer_name = list(imported_assy.children[1]._subshape_layers.values())[0] |
| 1154 | assert layer_name == "cube_2_right_face" |
| 1155 | |
| 1156 | |
| 1157 | def test_bad_step_file_import(tmpdir): |