]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
To fix salome test test.hdfs. Prevent a crash in case aDoc does not exist V9_12_0a1 V9_12_0a2
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Wed, 6 Sep 2023 14:59:24 +0000 (16:59 +0200)
committerjfa <jfa@opencascade.com>
Fri, 6 Oct 2023 22:42:37 +0000 (23:42 +0100)
src/ModuleBase/ModuleBase_Tools.cpp
src/PythonAPI/model/tests/tests.py
test.hdfs/CMakeLists.txt
test.hdfs/test_hdf.py
test.hdfs/testme.py

index da130c0ac9a06b74b275ef34a64404568c5811c7..9afabf39448b121d86ad9eb99a9443122188622f 100644 (file)
@@ -1429,6 +1429,12 @@ void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript)
 
   isDoingDisplay = true;
   DocumentPtr aDoc = thePart->partDoc();
+
+  if (!aDoc) {
+    // Prevent a crash in case aDoc does not exist
+    return;
+  }
+
   int aConstructionSize = aDoc->size(ModelAPI_ResultConstruction::group());
   int aGroupSize = aDoc->size(ModelAPI_ResultGroup::group());
   int aFieldSize = aDoc->size(ModelAPI_ResultField::group());
index dc36d0bd718aba75dee697213504d5db1eb05df8..c944daddea5515ff37fa92c709df7507333fa5d0 100644 (file)
@@ -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)
index 277d1414abcc318e5af93a0db5496b82fc355a1d..5de6b0682fbbf7f633165e9844d7cf009971c151 100644 (file)
@@ -63,7 +63,7 @@ FOREACH(tfile ${TEST_NAMES})
   ADD_TEST(NAME ${TEST_NAME}
            COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/testme.py" "${HDF_TEST_FILE}" "${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py")
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1")
-  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME};models_hdf")
+  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME};models_hdf;REQUIRE_X_SERVER")
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES TIMEOUT ${TIMEOUT})
 ENDFOREACH()
 
index 4a08b4089b7dd589dbf7e5235dec34aca64a071d..8911735b3efc61040c90c8799e33acecd664515f 100644 (file)
@@ -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()
index ccff03b4499634e08cd41a06e9f35d233878bc82..3a89659438163b92c3d8f2a95a5b0ef19d1691a5 100644 (file)
@@ -37,26 +37,41 @@ if __name__ == '__main__':
 
   tempfile = tempfile.NamedTemporaryFile()
   hdffile_basename = os.path.basename(hdffile)
+  test_hdfpy = "test_hdf.py"
+  if not os.path.exists(test_hdfpy):
+    # add absolute path in SHAPER install directory
+    test_hdfpy = os.path.join(os.getenv("SHAPER_ROOT_DIR"), "bin", "salome", "test", "HDFs", test_hdfpy)
+    if not os.path.exists(test_hdfpy):
+      raise Exception("test_hdf.py could not be found. Check your environment.")
   testlogfile = tempfile.name + "_" + hdffile_basename.replace(".", "_")
   tempfile.close()
 
   isOk = True
   error = ""
 
-  proc = subprocess.Popen(["runSalome.py", "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", "test_hdf.py", "args:" + hdffile + "," + testdatafile + "," + testlogfile], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  proc = subprocess.Popen(["runSalome.py", "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", test_hdfpy, "args:" + hdffile + "," + testdatafile + "," + testlogfile])
   try:
     proc.communicate(timeout = testTimeout)
-  except TimeoutExpired:
+  except subprocess.TimeoutExpired:
     isOk = False
-    proc.kill()
-    out, err = proc.communicate()
+    import salome_utils
+    port = salome_utils.getPortNumber()
+    import killSalomeWithPort
+    killSalomeWithPort.killMyPort(port)
     error = "Killed by CPU limit."
-    print(err)
+
+  assert isOk, "Test failed. {}".format(error)
 
   with open(testlogfile, 'r') as inputFile:
     s = inputFile.read()
-    print(s)
-    isOk = isOk and s.find("FAIL") < 0
+    #print("logfile: ", s)
+    if s.find("FAIL") > 0:
+      isOk = False
+      error = s
+    elif s.find("OK") < 0:
+      isOk = False
+      error = "Test not ended until OK. Maybe a SIGSEGV."
+
   try:
     os.remove(testlogfile)
   except: