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