Salome HOME
TestSaveOpen and TestSelectionInitialization: Fix tmp issue with parallel esy/testModelAPInewTMP
authoresy <emmanuel.streby@opencascade.com>
Tue, 28 Dec 2021 14:43:40 +0000 (15:43 +0100)
committeresy <emmanuel.streby@opencascade.com>
Tue, 28 Dec 2021 14:43:40 +0000 (15:43 +0100)
src/ModelAPI/Test/TestSaveOpen1.py
src/ModelAPI/Test/TestSaveOpen2.py
src/ModelAPI/Test/TestSelectionInitialization.py

index 8560b2125c730dddbe3e7de0ad33e691fdf9ca0c..587d640223f3f77c4486ba374572c95bbc6b2ade 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 from salome.shaper import model
+from tempfile import TemporaryDirectory
 from ModelAPI import *
 
 model.begin()
@@ -27,21 +28,22 @@ Point_name = Point_2.name()
 model.end()
 
 # check save document in a current folder
-aSession = ModelAPI_Session.get()
-aFiles = StringList()
-aSession.save(".", aFiles)
-assert(len(aFiles) == 1)
+with TemporaryDirectory() as tmp_dir:
+  aSession = ModelAPI_Session.get()
+  aFiles = StringList()
+  aSession.save(tmp_dir, aFiles)
+  assert(len(aFiles) == 1)
 
 # check open of the same document
-assert(aSession.load(".") == False) # error because this document is already opened
+  assert(aSession.load(tmp_dir) == False) # error because this document is already opened
 
 # close the current document
-aSession.closeAll()
+  aSession.closeAll()
 
 # open again: it must be correct now
-assert(aSession.load("."))
+  assert(aSession.load(tmp_dir))
 
 # check the created point is opened
-partSet = model.moduleDocument()
-assert(partSet.size("Features") == 1)
-assert(partSet.object("Features", 0).data().name() == Point_name)
+  partSet = model.moduleDocument()
+  assert(partSet.size("Features") == 1)
+  assert(partSet.object("Features", 0).data().name() == Point_name)
index 14a97b4fad8db35417daf0d473c3754e7c345a0c..26d31df79179b4cf55007a4da30dd6effcbe19ce 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 from salome.shaper import model
+from tempfile import TemporaryDirectory
 from ModelAPI import *
 
 model.begin()
@@ -33,36 +34,37 @@ Translation_1 = model.addTranslation(partSet, [model.selection("COMPOUND", "Part
 model.end()
 
 # check save document in a current folder
-aSession = ModelAPI_Session.get()
-aFiles = StringList()
-aSession.save(".", aFiles)
-assert(len(aFiles) == 3)
+with TemporaryDirectory() as tmp_dir:
+  aSession = ModelAPI_Session.get()
+  aFiles = StringList()
+  aSession.save(tmp_dir, aFiles)
+  assert(len(aFiles) == 3)
 
-# check open of the same document
-assert(aSession.load(".") == False) # error because this document is already opened
+  # check open of the same document
+  assert(aSession.load(tmp_dir) == False) # error because this document is already opened
 
-# close the current document
-aSession.closeAll()
+  # close the current document
+  aSession.closeAll()
 
-# open again: it must be correct now
-assert(aSession.load("."))
+  # open again: it must be correct now
+  assert(aSession.load(tmp_dir))
 
-# activate the Part of session
-model.begin()
-partSet = model.moduleDocument()
-assert(partSet.size("Features") == 2)
-aPart = objectToFeature(partSet.object("Features", 0))
-aPartResult = modelAPI_ResultPart(aPart.results()[0])
-aPartResult.activate()
-aPartDoc = aPartResult.partDoc()
-aSession.setActiveDocument(aPartDoc, True)
-model.do()
-# check the field result data
-aFieldFeature = aPartDoc.objectByName("Features", "Field_1")
-aFieldResult = modelAPI_ResultField(objectToFeature(aFieldFeature).results()[0])
-assert(aFieldResult.textLine(0) == "5")
-aSession.setActiveDocument(partSet, True)
-model.do()
-aTranslation = objectToFeature(partSet.objectByName("Features", "Translation_1"))
-partSet.setCurrentFeature(aTranslation, True)
-model.end()
+  # activate the Part of session
+  model.begin()
+  partSet = model.moduleDocument()
+  assert(partSet.size("Features") == 2)
+  aPart = objectToFeature(partSet.object("Features", 0))
+  aPartResult = modelAPI_ResultPart(aPart.results()[0])
+  aPartResult.activate()
+  aPartDoc = aPartResult.partDoc()
+  aSession.setActiveDocument(aPartDoc, True)
+  model.do()
+  # check the field result data
+  aFieldFeature = aPartDoc.objectByName("Features", "Field_1")
+  aFieldResult = modelAPI_ResultField(objectToFeature(aFieldFeature).results()[0])
+  assert(aFieldResult.textLine(0) == "5")
+  aSession.setActiveDocument(partSet, True)
+  model.do()
+  aTranslation = objectToFeature(partSet.objectByName("Features", "Translation_1"))
+  partSet.setCurrentFeature(aTranslation, True)
+  model.end()
index d244e90724faedf21f7b36d8b333c182d9cf9153..649f469fd43f3e938c34f1088a490d8c8b48eea4 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 from salome.shaper import model
+from tempfile import TemporaryDirectory
 from ModelAPI import *
 
 model.begin()
@@ -29,25 +30,26 @@ Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "Point_1"), 10)
 model.end()
 
 # save document in a current folder
-aSession = ModelAPI_Session.get()
-aFiles = StringList()
-aSession.save(".", aFiles)
-# close the current document
-aSession.closeAll()
-# open the saved document
-assert(aSession.load("."))
+with TemporaryDirectory() as tmp_dir:
+  aSession = ModelAPI_Session.get()
+  aFiles = StringList()
+  aSession.save(tmp_dir, aFiles)
+  # close the current document
+  aSession.closeAll()
+  # open the saved document
+  assert(aSession.load(tmp_dir))
 
-# activate the Part of session
-model.begin()
-partSet = model.moduleDocument()
-assert(partSet.size("Features") == 1)
-aPart = objectToFeature(partSet.object("Features", 0))
-aPartResult = modelAPI_ResultPart(aPart.results()[0])
-aPartResult.activate()
-aPartDoc = aPartResult.partDoc()
-aSession.setActiveDocument(aPartDoc, True)
-model.end()
+  # activate the Part of session
+  model.begin()
+  partSet = model.moduleDocument()
+  assert(partSet.size("Features") == 1)
+  aPart = objectToFeature(partSet.object("Features", 0))
+  aPartResult = modelAPI_ResultPart(aPart.results()[0])
+  aPartResult.activate()
+  aPartDoc = aPartResult.partDoc()
+  aSession.setActiveDocument(aPartDoc, True)
+  model.end()
 
-# check the sphere location (it should not be "Origin" - default one)
-aSphere = objectToFeature(aPartDoc.objectByName("Features", "Sphere_1"))
-assert(aSphere.selection("center_point").namingName() == "Point_1")
+  # check the sphere location (it should not be "Origin" - default one)
+  aSphere = objectToFeature(aPartDoc.objectByName("Features", "Sphere_1"))
+  assert(aSphere.selection("center_point").namingName() == "Point_1")