From: dbv Date: Mon, 6 Feb 2017 13:58:25 +0000 (+0300) Subject: Added test for testing number of sub-shapes. X-Git-Tag: V_2.7.0~288^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6f168f36db64b1b582c6297b274564d5ebd3981f;p=modules%2Fshaper.git Added test for testing number of sub-shapes. --- diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index cb2ce66a2..e4dcd7404 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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. diff --git a/test.models/bobine_film_reel.py b/test.models/bobine_film_reel.py index bbd0ddebc..44c4f24f9 100644 --- a/test.models/bobine_film_reel.py +++ b/test.models/bobine_film_reel.py @@ -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])