Files
cadquery/tests/test_exporters.py

52 lines
1.3 KiB
Python
Raw Normal View History

2013-04-20 20:33:35 -04:00
"""
Tests basic workplane functionality
"""
# core modules
import sys
2018-02-02 16:34:37 +01:00
import io
# my modules
2013-04-20 20:33:35 -04:00
from cadquery import *
from cadquery import exporters
from tests import BaseTest
2013-04-20 20:33:35 -04:00
class TestExporters(BaseTest):
def _exportBox(self, eType, stringsToFind):
2013-04-20 20:33:35 -04:00
"""
Exports a test object, and then looks for
2013-04-20 20:33:35 -04:00
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)
2018-02-02 16:34:37 +01:00
if eType == exporters.ExportTypes.AMF:
2018-02-02 16:34:37 +01:00
s = io.BytesIO()
else:
s = io.StringIO()
exporters.exportShape(p, eType, s, 0.1)
result = "{}".format(s.getvalue())
2013-04-20 20:33:35 -04:00
for q in stringsToFind:
self.assertTrue(result.find(q) > -1)
2013-04-20 20:33:35 -04:00
return result
2013-04-20 20:33:35 -04:00
def testSTL(self):
self._exportBox(exporters.ExportTypes.STL, ["facet normal"])
2013-04-20 20:33:35 -04:00
def testSVG(self):
self._exportBox(exporters.ExportTypes.SVG, ["<svg", "<g transform"])
2013-04-20 20:33:35 -04:00
def testAMF(self):
self._exportBox(exporters.ExportTypes.AMF, ["<amf units", "</object>"])
2013-04-20 20:33:35 -04:00
def testSTEP(self):
self._exportBox(exporters.ExportTypes.STEP, ["FILE_SCHEMA"])
2013-04-20 20:33:35 -04:00
def testTJS(self):
self._exportBox(
exporters.ExportTypes.TJS, ["vertices", "formatVersion", "faces"]
)