Test to make sure that importing plain assemblies has not been broken.
(tmpdir)
| 1166 | |
| 1167 | |
| 1168 | def test_plain_assembly_import(tmpdir): |
| 1169 | """ |
| 1170 | Test to make sure that importing plain assemblies has not been broken. |
| 1171 | """ |
| 1172 | |
| 1173 | # Simple cubes |
| 1174 | cube_1 = cq.Workplane().box(10, 10, 10) |
| 1175 | cube_2 = cq.Workplane().box(5, 5, 5) |
| 1176 | cube_3 = cq.Workplane().box(5, 5, 5) |
| 1177 | cube_4 = cq.Workplane().box(5, 5, 5) |
| 1178 | |
| 1179 | assy = cq.Assembly(name="top_level", loc=cq.Location(10, 10, 10)) |
| 1180 | assy.add(cube_1, color=cq.Color("green")) |
| 1181 | assy.add(cube_2, loc=cq.Location((10, 10, 10)), color=cq.Color("red")) |
| 1182 | assy.add(cube_3, loc=cq.Location((-10, -10, -10)), color=cq.Color("red")) |
| 1183 | assy.add(cube_4, loc=cq.Location((10, -10, -10)), color=cq.Color("red")) |
| 1184 | |
| 1185 | with chdir(tmpdir): |
| 1186 | # Export the assembly, but do not use the meta STEP export method |
| 1187 | assy.export("plain_assembly_step.step") |
| 1188 | |
| 1189 | # Import the STEP file back in |
| 1190 | imported_assy = cq.Assembly.importStep("plain_assembly_step.step") |
| 1191 | |
| 1192 | assert imported_assy.name == "top_level" |
| 1193 | |
| 1194 | # Check the locations |
| 1195 | assert imported_assy.children[0].loc.toTuple()[0] == (0.0, 0.0, 0.0,) |
| 1196 | assert imported_assy.children[1].loc.toTuple()[0] == (10.0, 10.0, 10.0,) |
| 1197 | assert imported_assy.children[2].loc.toTuple()[0] == (-10.0, -10.0, -10.0,) |
| 1198 | assert imported_assy.children[3].loc.toTuple()[0] == (10.0, -10.0, -10.0,) |
| 1199 | |
| 1200 | # Make sure the location of the top-level assembly was preserved |
| 1201 | assert imported_assy.loc.toTuple() == cq.Location((10, 10, 10)).toTuple() |
| 1202 | |
| 1203 | # Check the colors |
| 1204 | assert pytest.approx(imported_assy.children[0].color.toTuple(), rel=0.01) == ( |
| 1205 | 0.0, |
| 1206 | 1.0, |
| 1207 | 0.0, |
| 1208 | 1.0, |
| 1209 | ) # green |
| 1210 | assert pytest.approx(imported_assy.children[1].color.toTuple(), rel=0.01) == ( |
| 1211 | 1.0, |
| 1212 | 0.0, |
| 1213 | 0.0, |
| 1214 | 1.0, |
| 1215 | ) # red |
| 1216 | assert pytest.approx(imported_assy.children[2].color.toTuple(), rel=0.01) == ( |
| 1217 | 1.0, |
| 1218 | 0.0, |
| 1219 | 0.0, |
| 1220 | 1.0, |
| 1221 | ) # red |
| 1222 | assert pytest.approx(imported_assy.children[3].color.toTuple(), rel=0.01) == ( |
| 1223 | 1.0, |
| 1224 | 0.0, |
| 1225 | 0.0, |
nothing calls this directly
no test coverage detected