""" Tests basic workplane functionality """ # core modules import sys import io # my modules from cadquery import * from cadquery import exporters, importers from tests import BaseTest from OCP.GeomConvert import GeomConvert from OCP.BRepBuilderAPI import BRepBuilderAPI_MakeEdge class TestExporters(BaseTest): def _exportBox(self, eType, stringsToFind, tolerance=0.1, angularTolerance=0.1): """ Exports a test object, and then looks for all of the supplied strings to be in the result returns the result in case the case wants to do more checks also """ p = Workplane("XY").box(1, 2, 3) if eType == exporters.ExportTypes.AMF: s = io.BytesIO() else: s = io.StringIO() exporters.exportShape( p, eType, s, tolerance=tolerance, angularTolerance=angularTolerance ) result = "{}".format(s.getvalue()) for q in stringsToFind: self.assertTrue(result.find(q) > -1) return result def _box(self): return Workplane().box(1, 1, 1) def testSTL(self): self._exportBox(exporters.ExportTypes.STL, ["facet normal"]) exporters.export(self._box(), "out.stl") def testSVG(self): self._exportBox(exporters.ExportTypes.SVG, [""]) exporters.export(self._box(), "out.amf") def testSTEP(self): self._exportBox(exporters.ExportTypes.STEP, ["FILE_SCHEMA"]) exporters.export(self._box(), "out.step") def testTJS(self): self._exportBox( exporters.ExportTypes.TJS, ["vertices", "formatVersion", "faces"] ) exporters.export(self._box(), "out.tjs") def testVRML(self): exporters.export(self._box(), "out.vrml") with open("out.vrml") as f: res = f.read(10) assert res.startswith("#VRML V2.0") # export again to trigger all paths in the code exporters.export(self._box(), "out.vrml") def testVTP(self): exporters.export(self._box(), "out.vtp") with open("out.vtp") as f: res = f.read(100) assert res.startswith('\n