]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PythonAPI/model/tests/tests.py
Salome HOME
Added test for testing number of sub-shapes.
[modules/shaper.git] / src / PythonAPI / model / tests / tests.py
index cb2ce66a2ab9c4f8adc6f2d747d436a165d9d5bc..e4dcd74046c6753691454ecda61798bdf59cbc9a 100644 (file)
@@ -1,7 +1,15 @@
 from GeomAlgoAPI import *
+from GeomAPI import *
 import math
 
 
+aShapeTypes = {
+  GeomAPI_Shape.SOLID:  "GeomAPI_Shape.SOLID",
+  GeomAPI_Shape.FACE:   "GeomAPI_Shape.FACE",
+  GeomAPI_Shape.EDGE:   "GeomAPI_Shape.EDGE",
+  GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"}
+
+
 def generateTests(theFeature, theFeatureName, theTestsList = []):
   """ Generates tests for theFeature.
   :param theFeature: feature to test. Should be ModelHighAPI_Interface.
@@ -19,6 +27,20 @@ def generateTests(theFeature, theFeatureName, theTestsList = []):
       aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs())
     print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)
 
+  if "testNbSubShapes" in theTestsList or len(theTestsList) == 0:
+    aNbResults = len(theFeature.results())
+    for aShapeType in aShapeTypes:
+      aNbSubShapes = []
+      for anIndex in range(0, aNbResults):
+        aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
+        aNbResultSubShapes = 0
+        aShapeExplorer = GeomAPI_ShapeExplorer(aShape, aShapeType)
+        while aShapeExplorer.more():
+          aNbResultSubShapes += 1
+          aShapeExplorer.next();
+        aNbSubShapes.append(aNbResultSubShapes)
+      print "model.testNbSubShapes({}, {}, {})".format(theFeatureName, aShapeTypes[aShapeType], aNbSubShapes)
+
   if "testResultsVolumes" in theTestsList or len(theTestsList) == 0:
     aNbResults = len(theFeature.results())
     aResultsVolumes = []
@@ -50,6 +72,26 @@ def testNbSubResults(theFeature, theExpectedNbSubResults):
     assert (aNbSubResults == anExpectedNbSubResults), "Number of sub-results for result[{}]: {}. Expected: {}.".format(anIndex, aNbSubResults, anExpectedNbSubResults)
 
 
+def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes):
+  """ Tests number of feature sub-shapes of passed type for each result.
+  :param theFeature: feature to test.
+  :param theShapeType: shape type of sub-shapes to test.
+  :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()).
+  """
+  aNbResults = len(theFeature.results())
+  aListSize = len(theExpectedNbSubShapes)
+  assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+  for anIndex in range(0, aNbResults):
+    aNbResultSubShapes = 0
+    anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex]
+    aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
+    aShapeExplorer = GeomAPI_ShapeExplorer(aShape, theShapeType)
+    while aShapeExplorer.more():
+      aNbResultSubShapes += 1
+      aShapeExplorer.next();
+    assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes)
+
+
 def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10):
   """ Tests results volumes.
   :param theFeature: feature to test.