]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' into cgt/devCEA
authorClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 6 Feb 2017 15:22:45 +0000 (16:22 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 6 Feb 2017 15:22:45 +0000 (16:22 +0100)
src/PythonAPI/model/tests/tests.py
test.models/bobine_film_reel.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.
index bbd0ddebc73d4bae6c811b9ce8aba5baf5dacfaf..44c4f24f951d99be59fe84c58fe348e456bf584b 100644 (file)
@@ -109,6 +109,12 @@ model.do()
 ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_8/Face-SketchLine_7r-SketchLine_8r-SketchLine_10f-SketchLine_11f"), model.selection("FACE", "Sketch_8/Face-SketchLine_16f-SketchLine_17f-SketchLine_18r-SketchLine_19r"), model.selection("FACE", "Sketch_8/Face-SketchLine_12f-SketchLine_13f-SketchLine_14r-SketchLine_15r")], model.selection(), model.selection("FACE", "ExtrusionCut_2_1/Modfied_23"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_2_1")])
 model.end()
 
+from GeomAPI import GeomAPI_Shape
+
 model.testNbResults(ExtrusionCut_3, 1)
 model.testNbSubResults(ExtrusionCut_3, [0])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.FACE, [50])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.EDGE, [300])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.VERTEX, [600])
 model.testResultsVolumes(ExtrusionCut_3, [34439.077343526856566313654184341])