Salome HOME
updated copyright message
[modules/shaper.git] / src / ConnectorAPI / Test / TestExportToGEOMAllGroupsAndFields.py
index 0048ebc6b32e6b3b78a86f4cec2846a886155ed2..1ced591d58fc3c3acd045ced620678faa7191377 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
@@ -16,7 +16,6 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# -*- coding: utf-8 -*-
 
 import os
 import tempfile
@@ -24,6 +23,7 @@ import tempfile
 import sys
 import salome
 
+salome.standalone()
 salome.salome_init()
 theStudy = salome.myStudy
 
@@ -70,12 +70,6 @@ def dumpShaper(fileName):
   model.end()
   pass
 
-def getTmpFileName(ext):
-  tempdir = tempfile.gettempdir()
-  tmp_file = tempfile.NamedTemporaryFile(suffix=".%s"%ext, prefix='shaper_', dir=tempdir, delete=False)
-  tmp_filename = tmp_file.name
-  return tmp_filename
-
 def testGroupsAndFieldsExportToGEOM():
   model.begin()
   partSet = model.moduleDocument()
@@ -166,44 +160,41 @@ def checkResultInGEOM():
 
   field_1_GEOM = getSubObject(geomObject_1, 5)
   assert field_1_GEOM.GetName() == 'Field_solids'
-  assert field_1_GEOM.GetStep(0).GetValues() == [3.0]
+  assert field_1_GEOM.GetStep(1).GetValues() == [3.0]
 
   field_2_GEOM = getSubObject(geomObject_1, 6)
   assert field_2_GEOM.GetName() == 'Field_faces'
-  assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
+  assert field_2_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
 
   field_3_GEOM = getSubObject(geomObject_1, 7)
   assert field_3_GEOM.GetName() == 'Field_edges'
-  assert field_3_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
+  assert field_3_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
 
   field_4_GEOM = getSubObject(geomObject_1, 8)
   assert field_4_GEOM.GetName() == 'Field_vertices'
-  assert field_4_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
+  assert field_4_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
 
   pass
 
 def checkDump():
   # Dump the salome study (only CORBA modules, SHAPER dump is not in it)
-  tempdir = tempfile.gettempdir()
-  dumpFileGeomBase = "dump_test_geom"
-  dumpFileGeom = os.path.join(tempdir, "%s.py"%dumpFileGeomBase)
-  salome.myStudy.DumpStudy(tempdir, dumpFileGeomBase, True, False)
-
-  # Dump SHAPER
-  dumpFileShaper = os.path.join(tempdir, "dump_test_shaper.py")
-  dumpShaper(dumpFileShaper)
+  with tempfile.TemporaryDirectory() as tempdir:
+    dumpFileGeomBase = "dump_test_geom"
+    dumpFileGeom = os.path.join(tempdir, "%s.py"%dumpFileGeomBase)
+    salome.myStudy.DumpStudy(tempdir, dumpFileGeomBase, True, False)
 
-  # Load SHAPER dump
-  exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec'))
+    # Dump SHAPER
+    dumpFileShaper = os.path.join(tempdir, "dump_test_shaper.py")
+    dumpShaper(dumpFileShaper)
 
-  # Load GEOM dump
-  exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec'))
+    # Load SHAPER dump
+    exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec'))
 
-  # Clean files
-  files = [dumpFileGeom, dumpFileShaper]
-  for f in files:
-    os.remove(f)
+    # Load GEOM dump
+    exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec'))
 
+    # Clean files
+    files = [dumpFileGeom, dumpFileShaper]
   pass
 
 if __name__ == '__main__':