X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Ftests%2FTest%2Ftutorial_1.py;h=253d6bf1f73456b0c2f24df7218a98395648777e;hb=refs%2Ftags%2FV9_13_0b1;hp=5b49365cbdab24be4cd52602114bf03c8e85c9b6;hpb=3698a6d21be8092b91724c6e3687aae687fffc62;p=modules%2Fhomard.git diff --git a/src/tests/Test/tutorial_1.py b/src/tests/Test/tutorial_1.py index 5b49365c..253d6bf1 100755 --- a/src/tests/Test/tutorial_1.py +++ b/src/tests/Test/tutorial_1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2011-2016 CEA/DEN, EDF R&D +# Copyright (C) 2011-2024 CEA, EDF # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,7 +21,7 @@ Python script for HOMARD Test tutorial_1 associe au tutorial 1 """ -__revision__ = "V3.1" +__revision__ = "V4.07" #======================================================================== TEST_NAME = "tutorial_1" @@ -29,112 +29,132 @@ DEBUG = False N_ITER_TEST_FILE = 3 #======================================================================== import os -import tempfile import sys -import HOMARD -import salome # # ================================== -PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR') +PATH_HOMARD = os.getenv("HOMARD_ROOT_DIR") # Repertoire des scripts utilitaires 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() -# Repertoire des donnees du tutorial -DATA_TUTORIAL = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads") -DATA_TUTORIAL = os.path.normpath(DATA_TUTORIAL) -sys.path.append(DATA_TUTORIAL) -from tutorial_util import gzip_gunzip # ================================== -gzip_gunzip(DATA_TUTORIAL, 1, -1) +# Répertoires pour ce test +REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG) # ================================== - -salome.salome_init() +# +import salome +salome.salome_init_without_session() +import HOMARD import iparameters IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1)) IPAR.append("AP_MODULES_LIST", "Homard") # -#======================================================================== -#======================================================================== -def homard_exec(): +# +#========================= Debut de la fonction ================================== +# +def homard_exec(nom, ficmed, verbose=False): """ Python script for HOMARD """ + erreur = 0 + message = "" # - homard.UpdateStudy() + while not erreur : # - # Hypotheses - # ========== - hypo_1 = homard.CreateHypothesis('hypo_1') - hypo_1.SetUnifRefinUnRef(1) - # - # Cas - # === - case_1 = homard.CreateCase('case_1', 'MAILL', DATA_TUTORIAL+'/tutorial_1.00.med') - case_1.SetDirName(DIRCASE) - # - # Iterations - # ========== - # Iteration "iter_1_1" - iter_1_1 = case_1.NextIteration('iter_1_1') - iter_1_1.SetMeshName('MESH') - iter_1_1.SetMeshFile(DIRCASE+'/maill.01.med') - iter_1_1.AssociateHypo('hypo_1') - error = iter_1_1.Compute(1, 2) + # HOMARD.UpdateStudy() + # + # Hypotheses + # ========== + if verbose : + print(". Hypothèses") + hypo_1 = HOMARD.CreateHypothesis('hypo_1') + hypo_1.SetUnifRefinUnRef(1) + # + # Cas + # === + if verbose : + print(". Cas") + le_cas = HOMARD.CreateCase('case_1', nom, ficmed) + le_cas.SetDirName(DIRCASE) + # + # Itérations + # ========== + if verbose : + option = 2 + else : + option = 1 + if verbose : + print(". Itérations") + # Iteration "iter_1_1" + iter_1_1 = le_cas.NextIteration('iter_1_1') + iter_1_1.SetMeshName('MESH') + iter_1_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med")) + iter_1_1.AssociateHypo('hypo_1') + erreur = iter_1_1.Compute(1, option) + if erreur : + break - # Iteration "iter_1_2" - iter_1_2 = iter_1_1.NextIteration('iter_1_2') - iter_1_2.SetMeshName('MESH') - iter_1_2.SetMeshFile(DIRCASE+'/maill.02.med') - iter_1_2.AssociateHypo('hypo_1') - error = iter_1_2.Compute(1, 2) + # Iteration "iter_1_2" + iter_1_2 = iter_1_1.NextIteration('iter_1_2') + iter_1_2.SetMeshName('MESH') + iter_1_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med")) + iter_1_2.AssociateHypo('hypo_1') + erreur = iter_1_2.Compute(1, option) + if erreur : + break - # Iteration "iter_1_3" - iter_1_3 = iter_1_2.NextIteration('iter_1_3') - iter_1_3.SetMeshName('MESH') - iter_1_3.SetMeshFile(DIRCASE+'/maill.03.med') - iter_1_3.AssociateHypo('hypo_1') - error = iter_1_3.Compute(1, 2) + # Iteration "iter_1_3" + iter_1_3 = iter_1_2.NextIteration('iter_1_3') + iter_1_3.SetMeshName('MESH') + iter_1_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med")) + iter_1_3.AssociateHypo('hypo_1') + erreur = iter_1_3.Compute(1, option) + if erreur : + break # - return error - -#======================================================================== - -homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD') -assert homard is not None, "Impossible to load homard engine" -homard.SetLanguageShort("fr") + break + # + if erreur : + message += "Erreur au calcul de l'itération %d" % erreur + # + return erreur, message # -# Exec of HOMARD-SALOME +#========================== Fin de la fonction ================================== # -try : - 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) +ERREUR = 0 +MESSAGE = "" +while not ERREUR : + # + # A. Exec of HOMARD-SALOME + # + HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD') + assert HOMARD is not None, "Impossible to load homard engine" + HOMARD.SetLanguageShort("fr") # -# Test of the results + FICMED = os.path.join(REP_DATA, TEST_NAME+".00.med") + try: + ERREUR, MESSAGE = homard_exec("MAILL", FICMED, DEBUG) + except RuntimeError as eee: + ERREUR = 2 + MESSAGE = str(eee.message) + # + if ERREUR : + MESSAGE += "Pb in homard_exec" + break + # + # B. Test of the results + # + N_REP_TEST_FILE = N_ITER_TEST_FILE + DESTROY_DIR = not DEBUG + test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR) + # + break # -N_REP_TEST_FILE = N_ITER_TEST_FILE -DESTROY_DIR = not DEBUG -test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR) +if ERREUR: + raise Exception(MESSAGE) # -# ================================== -gzip_gunzip(DATA_TUTORIAL, 1, 1) -# ================================== # if salome.sg.hasDesktop(): salome.sg.updateObjBrowser()