Salome HOME
tests et tutorial
[modules/homard.git] / src / tests / Test / test_3.py
index ddaa7a16b5459767ce21e0accf19ffe839a6b759..87175a93f21e046b9d3a8474ef7fc6f1a7784468 100755 (executable)
@@ -21,7 +21,7 @@
 Python script for HOMARD
 Test test_3
 """
-__revision__ = "V3.1"
+__revision__ = "V4.04"
 
 #========================================================================
 TEST_NAME = "test_3"
@@ -30,7 +30,6 @@ N_BOUCLE = 2
 N_ITER_TEST_FILE = 2
 #========================================================================
 import os
-import tempfile
 import sys
 import HOMARD
 import salome
@@ -41,19 +40,11 @@ PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
 REP_PYTHON = os.path.normpath(REP_PYTHON)
 sys.path.append(REP_PYTHON)
-from test_util import remove_dir
+from test_util import get_dir
 from test_util import test_results
-# Repertoire des donnees du test
-REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
-REP_DATA = os.path.normpath(REP_DATA)
-# Repertoire des resultats
-if DEBUG :
-  DIRCASE = os.path.join("/tmp", TEST_NAME)
-  if ( os.path.isdir(DIRCASE) ) :
-    remove_dir(DIRCASE)
-  os.mkdir(DIRCASE)
-else :
-  DIRCASE = tempfile.mkdtemp()
+# ==================================
+# Répertoires pour ce test
+REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
 # ==================================
 
 salome.salome_init()
@@ -63,7 +54,7 @@ IPAR.append("AP_MODULES_LIST", "Homard")
 #
 #========================================================================
 #========================================================================
-def homard_exec(theStudy):
+def homard_exec():
   """
 Python script for HOMARD
   """
@@ -71,7 +62,7 @@ Python script for HOMARD
 #
   while not error :
   #
-    HOMARD.SetCurrentStudy(theStudy)
+    HOMARD.UpdateStudy()
   #
   # Creation of the boundaries
   # ==========================
@@ -94,25 +85,25 @@ Python script for HOMARD
   # ==========================
   # Uniform refinement
     hyponame = "hypo_" + TEST_NAME
-    print "-------- Creation of the hypothesis", hyponame
+    print("-------- Creation of the hypothesis", hyponame)
     hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
     hypo_test_3.SetUnifRefinUnRef(1)
-    print hyponame, " : zones utilisées :", hypo_test_3.GetZones()
-    print hyponame, " : champ utilisé :", hypo_test_3.GetFieldName()
-    print hyponame, " : composantes utilisées :", hypo_test_3.GetComps()
+    print(hyponame, " : zones utilisées :", hypo_test_3.GetZones())
+    print(hyponame, " : champ utilisé :", hypo_test_3.GetFieldName())
+    print(hyponame, " : composantes utilisées :", hypo_test_3.GetComps())
   #
     for num in range (N_BOUCLE+1) :
   #
-      print "-------- num =", num, "--------"
+      print("-------- num =", num, "--------")
   #
   # Creation of the case case_test_3
   # ===========================
       if ( num <= 1 ) :
-        print "-------- Creation of the case", TEST_NAME
+        print("-------- Creation of the case", TEST_NAME)
         mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
         case_test_3 = HOMARD.CreateCase(TEST_NAME, 'MOYEU', mesh_file)
         case_test_3.SetDirName(DIRCASE)
-        case_test_3.AddBoundaryGroup('courbes', '')
+        case_test_3.AddBoundary('courbes')
         case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
         case_test_3.AddBoundaryGroup('cyl_int', 'INT')
         case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
@@ -122,7 +113,7 @@ Python script for HOMARD
   # ==========================
   # Creation of the iteration 1
       iter_name = "I_" + TEST_NAME + "_1"
-      print "-------- Creation of the iteration", iter_name
+      print("-------- Creation of the iteration", iter_name)
       iter_test_3_1 = case_test_3.NextIteration(iter_name)
       iter_test_3_1.SetMeshName('MOYEU_1')
       iter_test_3_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
@@ -134,7 +125,7 @@ Python script for HOMARD
 
   # Creation of the iteration 2
       iter_name = "I_" + TEST_NAME + "_2"
-      print "-------- Creation of the iteration", iter_name
+      print("-------- Creation of the iteration", iter_name)
       iter_test_3_2 = iter_test_3_1.NextIteration(iter_name)
       iter_test_3_2.SetMeshName('MOYEU_2')
       iter_test_3_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
@@ -150,7 +141,7 @@ Python script for HOMARD
       scriptfile = os.path.normpath(scriptfile)
       dirname = DIRCASE
       yacsname = "YACS_" + TEST_NAME
-      print "-------- Creation of the schema", yacsname
+      print("-------- Creation of the schema", yacsname)
       yacs_test_3 = case_test_3.CreateYACSSchema(yacsname, scriptfile, dirname, mesh_file)
       yacs_test_3.SetType(2)
       yacs_test_3.SetMaxIter(2)
@@ -163,7 +154,7 @@ Python script for HOMARD
   # ============
   # Destruction of the schema, sauf a la fin
       if ( num < N_BOUCLE ) :
-        print "-------- Destruction of the schema", yacs_test_3.GetName()
+        print("-------- Destruction of the schema", yacs_test_3.GetName())
         error = yacs_test_3.Delete(1)
         if error :
           error = 10*num + 6
@@ -171,27 +162,27 @@ Python script for HOMARD
   # After the first loop, the case is deleted, except the final mesh files
   # All the iterations are deleted
       if ( num == 0 ) :
-        print "-------- Destruction of the case", case_test_3.GetName()
+        print("-------- Destruction of the case", case_test_3.GetName())
         error = case_test_3.Delete(0)
         if error :
           break
   # After the second loop, the iterations are deleted, with the final mesh files
       elif ( num == 1 ) :
   # Recursive destruction of the iterations
-        print "-------- Recursive destruction of the iteration", iter_test_3_1.GetName()
+        print("-------- Recursive destruction of the iteration", iter_test_3_1.GetName())
         error = iter_test_3_1.Delete(1)
         if error :
           error = 10*num + 3
           break
   # Destruction and creation of the hypothese
         if ( num == 1 ) :
-          print "-------- Destruction of the hypothese", hypo_test_3.GetName()
+          print("-------- Destruction of the hypothese", hypo_test_3.GetName())
           error = hypo_test_3.Delete()
           if error :
             error = 10*num + 4
             break
           hyponame = "hypo_test_3"
-          print "-------- Creation of the hypothesis", hyponame
+          print("-------- Creation of the hypothesis", hyponame)
           hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
           hypo_test_3.SetUnifRefinUnRef(1)
   #
@@ -208,11 +199,11 @@ HOMARD.SetLanguageShort("fr")
 # Exec of HOMARD-SALOME
 #
 try :
-  ERROR = homard_exec(salome.myStudy)
+  ERROR = homard_exec()
   if ERROR :
     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
-except Exception, eee:
-  raise Exception('Pb in homard_exec: '+eee.message)
+except RuntimeError as eee:
+  raise Exception('Pb in homard_exec: '+str(eee.message))
 #
 # Test of the results
 #
@@ -221,6 +212,6 @@ DESTROY_DIR = not DEBUG
 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
 #
 if salome.sg.hasDesktop():
-  salome.sg.updateObjBrowser(True)
+  salome.sg.updateObjBrowser()
   iparameters.getSession().restoreVisualState(1)