3 Unit test of ExchangePlugin_TestImport class
5 #=========================================================================
6 # Initialization of the test
7 #=========================================================================
9 from GeomDataAPI import *
10 from GeomAlgoAPI import *
15 __updated__ = "2015-05-22"
17 aSession = ModelAPI_Session.get()
18 #=========================================================================
19 # Common test function
20 #=========================================================================
21 def testImport(theType, theFile, theVolume, theDelta):
22 # Create a part for import
23 aSession.startOperation()
24 aPartFeature = aSession.moduleDocument().addFeature("Part")
25 aSession.finishOperation()
26 aPart = aSession.activeDocument()
28 aSession.startOperation()
29 aFeatureKind = "Import"
30 anImportFeature = aPart.addFeature(aFeatureKind)
31 assert anImportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
32 aFieldName = "file_path"
33 file = anImportFeature.string(aFieldName)
34 assert file, "{0}: Can not receive string field {1}".format(theType, aFieldName)
35 file.setValue(theFile)
36 anImportFeature.execute()
37 aSession.finishOperation()
40 assert anImportFeature.error() == '', "{0}: The error after execution: {1}".format(theType, anImportFeature.error())
41 assert len(anImportFeature.results()) == 1, "{0}: Wrong number of results: expected = 1, real = {1}".format(theType, len(anImportFeature.results()))
42 aResultBody = modelAPI_ResultBody(anImportFeature.firstResult())
43 assert aResultBody, "{0}: The result is not a body".format(theType)
44 aShape = aResultBody.shape()
45 assert aShape, "{0}: The body does not have a shape".format(theType)
48 aRefVolume = theVolume
49 aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape)
50 assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume)
52 if __name__ == '__main__':
53 #=========================================================================
54 # Create a shape imported from BREP
55 #=========================================================================
56 testImport("BREP", "Data/solid.brep", 259982.29715, 10 ** -5)
57 testImport("BRP", "Data/solid.brp", 259982.29715, 10 ** -5)
58 #=========================================================================
59 # Create a shape imported from STEP
60 #=========================================================================
61 testImport("STP", "Data/screw.stp", 3.78827059338e-06, 10 ** -17)
62 testImport("STEP", "Data/screw.step", 3.78827059338e-06, 10 ** -17)
63 #=========================================================================
64 # Create a shape imported from IGES
65 #=========================================================================
66 testImport("IGES", "Data/bearing.iges", 6.86980756235e-14, 10 ** -25)
67 testImport("IGS", "Data/bearing.igs", 6.86980756235e-14, 10 ** -25)
68 #=========================================================================
70 #=========================================================================