Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelAPI / Test / TestSaveOpen2.py
index 509da78216c45ad535a41052e6b8c6fc535b381e..b48337be0f1b0c5c3c404fb2ff381861a1511e1e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+# Copyright (C) 2014-2023  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -17,9 +17,8 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-# -*- coding: utf-8 -*-
-
 from salome.shaper import model
+from tempfile import TemporaryDirectory
 from ModelAPI import *
 
 model.begin()
@@ -35,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()