Merge pull request #4 from justbuchanan/step-segfault
Add test case that loads an invalid STEP file
This commit is contained in:
@ -8,6 +8,7 @@ import urllib as urlreader
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from OCC.STEPControl import STEPControl_Reader
|
from OCC.STEPControl import STEPControl_Reader
|
||||||
|
import OCC.IFSelect
|
||||||
|
|
||||||
|
|
||||||
class ImportTypes:
|
class ImportTypes:
|
||||||
@ -38,9 +39,10 @@ def importStep(fileName):
|
|||||||
:param fileName: The path and name of the STEP file to be imported
|
:param fileName: The path and name of the STEP file to be imported
|
||||||
"""
|
"""
|
||||||
# Now read and return the shape
|
# Now read and return the shape
|
||||||
try:
|
|
||||||
reader = STEPControl_Reader()
|
reader = STEPControl_Reader()
|
||||||
reader.ReadFile(fileName)
|
readStatus = reader.ReadFile(fileName)
|
||||||
|
if readStatus != OCC.IFSelect.IFSelect_RetDone:
|
||||||
|
raise ValueError("STEP File could not be loaded")
|
||||||
reader.TransferRoot()
|
reader.TransferRoot()
|
||||||
|
|
||||||
occ_shapes = []
|
occ_shapes = []
|
||||||
@ -53,8 +55,6 @@ def importStep(fileName):
|
|||||||
solids.append(Shape.cast(shape))
|
solids.append(Shape.cast(shape))
|
||||||
|
|
||||||
return cadquery.Workplane("XY").newObject(solids)
|
return cadquery.Workplane("XY").newObject(solids)
|
||||||
except:
|
|
||||||
raise ValueError("STEP File Could not be loaded")
|
|
||||||
|
|
||||||
# Loads a STEP file from an URL into a CQ.Workplane object
|
# Loads a STEP file from an URL into a CQ.Workplane object
|
||||||
|
|
||||||
|
@ -48,6 +48,16 @@ class TestImporters(BaseTest):
|
|||||||
"""
|
"""
|
||||||
self.importBox(importers.ImportTypes.STEP, OUTDIR + "/tempSTEP.step")
|
self.importBox(importers.ImportTypes.STEP, OUTDIR + "/tempSTEP.step")
|
||||||
|
|
||||||
|
def testInvalidSTEP(self):
|
||||||
|
"""
|
||||||
|
Attempting to load an invalid STEP file should throw an exception, but
|
||||||
|
not segfault.
|
||||||
|
"""
|
||||||
|
tmpfile = OUTDIR + "/badSTEP.step"
|
||||||
|
with open(tmpfile, 'w') as f: f.write("invalid STEP file")
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
importers.importShape(importers.ImportTypes.STEP, tmpfile)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import unittest
|
import unittest
|
||||||
|
Reference in New Issue
Block a user