X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPythonAPI%2Fmodel%2Ftests%2Ftests.py;h=e088f7c749723377713df2a22937eb330ffa068c;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=79ac48d13ebedfa9aa899c33c5dcabcff3ffcf5f;hpb=c0e273c1479a9940dbe4f966853c82a6b8709d88;p=modules%2Fshaper.git diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 79ac48d13..e088f7c74 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2022 CEA/DEN, EDF R&D +# Copyright (C) 2014-2024 CEA, EDF # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,7 +20,7 @@ from GeomAlgoAPI import * from GeomAPI import * from GeomDataAPI import * -from ModelAPI import ModelAPI_Feature, ModelAPI_Session +from ModelAPI import ModelAPI_Feature, ModelAPI_Session, objectToFeature from ModelHighAPI import * import math from salome.shaper.model import sketcher @@ -69,14 +69,14 @@ def generateTests(theFeature, theFeatureName, theTestsList = []): aNbResults = len(theFeature.results()) aResultsVolumes = [] for anIndex in range(0, aNbResults): - aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())) + aResultsVolumes.append(GeomAlgoAPI_ShapeTools.volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())) print("model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes))) if "testResultsAreas" in theTestsList or len(theTestsList) == 0: aNbResults = len(theFeature.results()) aResultsAreas = [] for anIndex in range(0, aNbResults): - aResultsAreas.append(GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape())) + aResultsAreas.append(GeomAlgoAPI_ShapeTools.area(theFeature.results()[anIndex].resultSubShapePair()[0].shape())) print("model.testResultsAreas({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsAreas))) @@ -123,6 +123,64 @@ def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes): assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes) +def testNbUniqueSubShapes(theFeature, theShapeType, theExpectedNbSubShapes): + """ Tests number of unique 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()). + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + 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] + aNbResultSubShapes = aResults[anIndex].shape().subShapes(theShapeType, True).size() + assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes) + + +def testCompound(theFeature, NbSubRes, NbSolid, NbFace, NbEdge, NbVertex): + """ Tests number of unique sub-shapes in compound result + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + assert (aNbResults == 1), "Number of results: {} not equal to 1.".format(aNbResults) + assert aResults[0].shape().isCompound(), "Result shape type: {}. Expected: COMPOUND.".format(aResults[0].shape().shapeTypeStr()) + testNbSubResults(theFeature, NbSubRes) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SOLID, NbSolid) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex) + + +def testCompSolid(theFeature, NbSubRes, NbSolid, NbFace, NbEdge, NbVertex): + """ Tests number of unique sub-shapes in compsolid result + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + assert (aNbResults == 1), "Number of results: {} not equal to 1.".format(aNbResults) + assert aResults[0].shape().isCompSolid(), "Result shape type: {}. Expected: COMPSOLID.".format(aResults[0].shape().shapeTypeStr()) + testNbSubResults(theFeature, NbSubRes) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SOLID, NbSolid) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex) + + +def testResults(theFeature, NbRes, NbSubRes, NbShell, NbFace, NbEdge, NbVertex): + """ Tests numbers of unique sub-shapes in the results + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + assert (aNbResults == NbRes), "Number of results: {} not equal to {}}.".format(aNbResults, NbRes) + testNbSubResults(theFeature, NbSubRes) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SHELL, NbShell) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge) + testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex) + + def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 7): """ Tests results volumes. :param theFeature: feature to test. @@ -133,7 +191,7 @@ def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDi aListSize = len(theExpectedResultsVolumes) assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize) for anIndex in range(0, aNbResults): - aResultVolume = GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()) + aResultVolume = GeomAlgoAPI_ShapeTools.volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()) aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0") anExpectedResultVolume = theExpectedResultsVolumes[anIndex] anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0") @@ -150,7 +208,7 @@ def testResultsAreas(theFeature, theExpectedResultsVolumes, theNbSignificantDigi aListSize = len(theExpectedResultsVolumes) assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize) for anIndex in range(0, aNbResults): - aResultVolume = GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape()) + aResultVolume = GeomAlgoAPI_ShapeTools.area(theFeature.results()[anIndex].resultSubShapePair()[0].shape()) aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0") anExpectedResultVolume = theExpectedResultsVolumes[anIndex] anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0") @@ -386,3 +444,32 @@ def checkFilter(thePartDoc, theModel, theFilter, theShapesList): assert aFiltersFactory.isValid(theFilter.feature(), parent, shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res) if needUndo: theModel.undo() + +def checkFeaturesValidity(thePartDoc): + """ Check that the features are not in error + """ + aFactory = ModelAPI_Session.get().validators() + + nbFeatures = thePartDoc.size("Features") + + assert nbFeatures>0, "No features found in part doc" + + for i in range(nbFeatures): + partObject = thePartDoc.object("Features", i) + # Check the data + partObjectData = partObject.data() + name = partObjectData.name() + error = partObjectData.error() + # raise the error message if there is one + assert error == '', "The feature data {0} is in error: {1}".format(name, error) + # raise an error if the the feature is not valid (without error message) + assert partObject.data().isValid(), "The feature data {0} is in error.".format(name) + # Same checks for the feature itself + feature = objectToFeature(partObject) + if feature is None: + # Folders are not real features + continue + # raise the error message if there is one + assert error == '', "The feature {0} is in error: {1}".format(name, error) + # raise an error if the the feature is not valid (without error message) + assert aFactory.validate(feature), "The feature {0} is in error.".format(name)