From: Christophe Bourcier Date: Fri, 8 Sep 2023 15:00:40 +0000 (+0200) Subject: Add features validity check in test.hdfs X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a3d18e59d7374e6b518453b3ded62a601ce7c813;p=modules%2Fshaper.git Add features validity check in test.hdfs --- diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index dc36d0bd7..c944dadde 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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 @@ -444,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) diff --git a/test.hdfs/test_hdf.py b/test.hdfs/test_hdf.py index 4a08b4089..8911735b3 100644 --- a/test.hdfs/test_hdf.py +++ b/test.hdfs/test_hdf.py @@ -64,6 +64,10 @@ class TestHDF(unittest.TestCase): self.session.setActiveDocument(self.partSet) self.session.finishOperation() + # Check that the features are not in error + Part_1_doc = aPart.partDoc() + + model.checkFeaturesValidity(Part_1_doc) # check reference data exec(open(self.reffile, "rb").read(), globals(), aPartsList) @@ -75,11 +79,16 @@ if __name__ == "__main__": TestHDF.reffile = sys.argv[2] if len(sys.argv) > 3: errFile = open(sys.argv[3], 'w') + else: + # to ease debugging, display the log in embedded python console if no log file is provided + # when calling salome in command line for instance + # runSalome.py --splash 0 test_hdf.py args:BearingSeparator.hdf,BearingSeparator.py + errFile = None aTest = unittest.TestLoader().loadTestsFromTestCase(TestHDF) unittest.TextTestRunner(stream=errFile).run(aTest) - errFile.close() - #import qtsalome - #qtsalome.qApp.closeAllWindows() - import signal - os.kill(os.getpid(),signal.SIGKILL) + if errFile: + errFile.close() + + # Quit SALOME the clean way + sys.exit()