1 from GeomAlgoAPI import *
7 GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID",
8 GeomAPI_Shape.FACE: "GeomAPI_Shape.FACE",
9 GeomAPI_Shape.EDGE: "GeomAPI_Shape.EDGE",
10 GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"}
13 def generateTests(theFeature, theFeatureName, theTestsList = []):
14 """ Generates tests for theFeature.
15 :param theFeature: feature to test. Should be ModelHighAPI_Interface.
16 :param theFeatureName: feature name to put in test commands.
17 :param theTestsList: list of test to be generated. If empty generates all tests.
19 if "testNbResults" in theTestsList or len(theTestsList) == 0:
20 aNbResults = len(theFeature.results())
21 print "model.testNbResults({}, {})".format(theFeatureName, aNbResults)
23 if "testNbSubResults" in theTestsList or len(theTestsList) == 0:
24 aNbResults = len(theFeature.results())
26 for anIndex in range(0, aNbResults):
27 aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs())
28 print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)
30 if "testNbSubShapes" in theTestsList or len(theTestsList) == 0:
31 aNbResults = len(theFeature.results())
32 for aShapeType in aShapeTypes:
34 for anIndex in range(0, aNbResults):
35 aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
36 aNbResultSubShapes = 0
37 aShapeExplorer = GeomAPI_ShapeExplorer(aShape, aShapeType)
38 while aShapeExplorer.more():
39 aNbResultSubShapes += 1
40 aShapeExplorer.next();
41 aNbSubShapes.append(aNbResultSubShapes)
42 print "model.testNbSubShapes({}, {}, {})".format(theFeatureName, aShapeTypes[aShapeType], aNbSubShapes)
44 if "testResultsVolumes" in theTestsList or len(theTestsList) == 0:
45 aNbResults = len(theFeature.results())
47 for anIndex in range(0, aNbResults):
48 aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
49 print "model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes))
52 def testNbResults(theFeature, theExpectedNbResults):
53 """ Tests number of feature results.
54 :param theFeature: feature to test.
55 :param theExpectedNbResults: expected number of results.
57 aNbResults = len(theFeature.results())
58 assert (aNbResults == theExpectedNbResults), "Number of results: {}. Expected: {}.".format(aNbResults, theExpectedNbResults)
61 def testNbSubResults(theFeature, theExpectedNbSubResults):
62 """ Tests number of feature sub-results for each result.
63 :param theFeature: feature to test.
64 :param theExpectedNbSubResults: list of sub-results numbers. Size of list should be equal to len(theFeature.results()).
66 aNbResults = len(theFeature.results())
67 aListSize = len(theExpectedNbSubResults)
68 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
69 for anIndex in range(0, aNbResults):
70 aNbSubResults = theFeature.results()[anIndex].numberOfSubs()
71 anExpectedNbSubResults = theExpectedNbSubResults[anIndex]
72 assert (aNbSubResults == anExpectedNbSubResults), "Number of sub-results for result[{}]: {}. Expected: {}.".format(anIndex, aNbSubResults, anExpectedNbSubResults)
75 def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes):
76 """ Tests number of feature sub-shapes of passed type for each result.
77 :param theFeature: feature to test.
78 :param theShapeType: shape type of sub-shapes to test.
79 :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()).
81 aNbResults = len(theFeature.results())
82 aListSize = len(theExpectedNbSubShapes)
83 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
84 for anIndex in range(0, aNbResults):
85 aNbResultSubShapes = 0
86 anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex]
87 aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
88 aShapeExplorer = GeomAPI_ShapeExplorer(aShape, theShapeType)
89 while aShapeExplorer.more():
90 aNbResultSubShapes += 1
91 aShapeExplorer.next();
92 assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes)
95 def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10):
96 """ Tests results volumes.
97 :param theFeature: feature to test.
98 :param theExpectedResultsVolumes: list of results volumes. Size of list should be equal to len(theFeature.results()).
100 aNbResults = len(theFeature.results())
101 aListSize = len(theExpectedResultsVolumes)
102 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
103 for anIndex in range(0, aNbResults):
104 aResultVolume = GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())
105 aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0")
106 anExpectedResultVolume = theExpectedResultsVolumes[anIndex]
107 anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
108 assert (aResultVolumeStr[:theNbSignificantDigits] == anExpectedResultVolumeStr[:theNbSignificantDigits]), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)