From d4e43dab1260b18c25db0b0b696f3b50a90b829d Mon Sep 17 00:00:00 2001 From: eficas <> Date: Mon, 23 Jan 2006 09:44:22 +0000 Subject: [PATCH] CCAR: ajout tests de adaptation pour validation parametres --- Tests/testcomm/a.comm | 2 + Tests/testcomm/c.comm | 14 +++++ Tests/testcomm/e.comm | 70 +++++++++++++++++++++++++ Tests/testcomm/f.comm | 18 +++++++ Tests/testcomm/g.comm | 11 ++++ Tests/testcomm/testaster1.py | 2 +- Tests/testcomm/testaster10.py | 4 +- Tests/testcomm/testaster2.py | 2 +- Tests/testcomm/testaster3.py | 2 +- Tests/testcomm/testaster4.py | 2 +- Tests/testcomm/testaster5.py | 8 ++- Tests/testcomm/testaster6.py | 2 +- Tests/testcomm/testaster7.py | 8 ++- Tests/testcomm/testaster8.py | 2 +- Tests/testcomm/testaster9.py | 2 +- Tests/testelem/params.comm | 26 ++++++++++ Tests/testelem/testjdc1.py | 89 ++++++++++++++++++++++++++++++-- Tests/testelem/testjdc3.py | 84 ++++++++++++++++++++++++++++++ Tests/testelem/testjdc4.py | 56 ++++++++++++++++++++ Tests/testelem/testsimp1.py | 24 +++++++++ Tests/testelem/testsimp3.py | 20 +++++++ Tests/testelem/testvalidator2.py | 25 +++++++++ 22 files changed, 456 insertions(+), 17 deletions(-) create mode 100644 Tests/testcomm/e.comm create mode 100644 Tests/testcomm/f.comm create mode 100644 Tests/testcomm/g.comm create mode 100644 Tests/testelem/params.comm create mode 100644 Tests/testelem/testjdc4.py diff --git a/Tests/testcomm/a.comm b/Tests/testcomm/a.comm index 812f1bc0..665f63fe 100644 --- a/Tests/testcomm/a.comm +++ b/Tests/testcomm/a.comm @@ -1,3 +1,5 @@ DEBUT() inf=1 +p2=inf+1 +p3=sin(p2) FIN() diff --git a/Tests/testcomm/c.comm b/Tests/testcomm/c.comm index e4dfab33..36906c57 100644 --- a/Tests/testcomm/c.comm +++ b/Tests/testcomm/c.comm @@ -4,11 +4,13 @@ RAYCRA=1. EPCRA=0.1 S_CR=3.1415*(RAYCRA**2-(RAYCRA-EPCRA)**2) T_CR=3.1415 +NOMF="nomfichier" n=2 MA=LIRE_MAILLAGE( ) MO=AFFE_MODELE( MAILLAGE=MA, + #test de validateur GEOM (typ=grma) avec grma derive de GEOM AFFE=(_F(GROUP_MA = ('LI1'), PHENOMENE = 'MECANIQUE', MODELISATION = 'DIS_TR'), @@ -32,4 +34,16 @@ CAREG=AFFE_CARA_ELEM(MODELE=MO, ), ); +DEFI_FICHIER(UNITE=50, FICHIER='./REPE_OUT/zzzz206a_resu.mail') +#test de validateur LongStr avec parametre instance de PARAMETRE +DEFI_FICHIER(UNITE=50, FICHIER=NOMF) +#test de validateur LongStr avec parametre instance de Formula +u=DEFI_FICHIER( FICHIER=NOMF*2) +DEFI_FICHIER (ACTION='LIBERER',UNITE=50) +#test de validateur d'objet entier (typ='I'), instance de la classe entier +DEFI_FICHIER (ACTION='LIBERER',UNITE=u) + +# test de validateur qui accepte tout (typ=assd) +IMPR_CO(CO=MA) + FIN() diff --git a/Tests/testcomm/e.comm b/Tests/testcomm/e.comm new file mode 100644 index 00000000..ffd11857 --- /dev/null +++ b/Tests/testcomm/e.comm @@ -0,0 +1,70 @@ +DEBUT() +MAYA=LIRE_MAILLAGE() + +MAYA=DEFI_GROUP( reuse=MAYA, MAILLAGE=MAYA, + CREA_GROUP_MA=_F( NOM = 'TOUT', TOUT = 'OUI')) + +BARRE1=AFFE_MODELE( MAILLAGE=MAYA, + AFFE=_F( GROUP_MA='SS1', + MODELISATION = 'POU_D_E', + PHENOMENE = 'MECANIQUE')) +# +MATERIO1=DEFI_MATERIAU( ELAS=_F( RHO = 1.E08, NU = 0.3, E = 1.E10)) + +MATERIO2=DEFI_MATERIAU( ELAS=_F( RHO = 0., NU = 0., E = 1.E15)) +# +CHMAT=AFFE_MATERIAU( MAILLAGE=MAYA,AFFE=( + #_F( TOUT = 'OUI', MATER = MATERIO1), + _F( GROUP_MA = 'SS1', MATER = MATERIO1), + _F( GROUP_MA = 'SS2', MATER = MATERIO1), + _F( GROUP_MA = 'SS3', MATER = MATERIO1), + _F( GROUP_MA = 'RIGIDE', MATER = MATERIO2), +)) # commentaire test + +CARA1=AFFE_CARA_ELEM( MODELE=BARRE1, + POUTRE=_F( + GROUP_MA = 'TOUT', + SECTION = 'CERCLE', + CARA = ('R', 'EP',), + VALE = (0.1, 0.01,))) + +GUIDAGE1=AFFE_CHAR_MECA( MODELE=BARRE1,DDL_IMPO=( + _F( GROUP_MA='SS1', + DX = 0., DZ = 0., DRX = 0., DRY = 0.), + _F( GROUP_NO = 'L1', DY = 0., DRZ = 0.), + )) + +K_ELEM1=CALC_MATR_ELEM( MODELE=BARRE1, + CARA_ELEM=CARA1, + CHAM_MATER=CHMAT, + OPTION='RIGI_MECA', + CHARGE=GUIDAGE1) + +NUM1=NUME_DDL( MATR_RIGI=K_ELEM1) + +# +K_ASSE1=ASSE_MATRICE( MATR_ELEM=K_ELEM1, + NUME_DDL=NUM1) + +MODESTA1=MODE_STATIQUE( MATR_RIGI=K_ASSE1, + MODE_STAT=_F( + GROUP_NO=('L12'), + AVEC_CMP = ('DY','DRZ'), + )) + +# parse: -affectation + +DS1=[None]*5 +DS2=[None]*5 +DS3=[None]*5 +DS4=[None]*5 +CHS1=[None]*5 +CHS2=[None]*5 + +# parse: +affectation + +for k in range(1,5): + DS1[k] = CREA_CHAMP( OPERATION='EXTR', TYPE_CHAM='NOEU_DEPL_R', + RESULTAT= MODESTA1, NUME_ORDRE=k, NOM_CHAM = 'DEPL'); + +FIN() diff --git a/Tests/testcomm/f.comm b/Tests/testcomm/f.comm new file mode 100644 index 00000000..d15a6179 --- /dev/null +++ b/Tests/testcomm/f.comm @@ -0,0 +1,18 @@ +from Numeric import size + +DEBUT() + +# Definition des parametres de l'excitation sinusoidale +freq=1500.0 +periode=1.0/freq +pas=periode/100.0 + +LISTTM=DEFI_LIST_REEL(DEBUT=0.0*periode, + INTERVALLE=_F(JUSQU_A=100.0*periode, + PAS=pas,),); + +LISTRD=DEFI_LIST_REEL(DEBUT=(98.0)*periode+pas, + INTERVALLE=_F(JUSQU_A=(100.0)*periode, + PAS=pas,),); + +FIN() diff --git a/Tests/testcomm/g.comm b/Tests/testcomm/g.comm new file mode 100644 index 00000000..f8393148 --- /dev/null +++ b/Tests/testcomm/g.comm @@ -0,0 +1,11 @@ +DEBUT() +sensible=[2.1E11, 0.3, 1.E-6, 1.E-6, ] + +# parse: -affectation +n=len(sensible) +PS=[None]*n + +for i in range(n): + PS[i]=DEFI_PARA_SENSI(VALE=sensible[i]) + +FIN() diff --git a/Tests/testcomm/testaster1.py b/Tests/testcomm/testaster1.py index b3c8f1d4..6984f60b 100644 --- a/Tests/testcomm/testaster1.py +++ b/Tests/testcomm/testaster1.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster10.py b/Tests/testcomm/testaster10.py index 850a651e..8e7a4053 100644 --- a/Tests/testcomm/testaster10.py +++ b/Tests/testcomm/testaster10.py @@ -17,12 +17,10 @@ class TestCase(unittest.TestCase): i=0 for f in glob.glob(os.path.join(ASTERDIR,"z*.comm")): - if f == os.path.join(ASTERDIR,"zzzz118c.comm"):continue - if f == os.path.join(ASTERDIR,"zzzz118d.comm"):continue ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster2.py b/Tests/testcomm/testaster2.py index 97de2bee..729c6633 100644 --- a/Tests/testcomm/testaster2.py +++ b/Tests/testcomm/testaster2.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster3.py b/Tests/testcomm/testaster3.py index 85d4d0d2..f0338b29 100644 --- a/Tests/testcomm/testaster3.py +++ b/Tests/testcomm/testaster3.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster4.py b/Tests/testcomm/testaster4.py index 66fcd829..9d34bdc5 100644 --- a/Tests/testcomm/testaster4.py +++ b/Tests/testcomm/testaster4.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster5.py b/Tests/testcomm/testaster5.py index 91d9917d..8b4687fa 100644 --- a/Tests/testcomm/testaster5.py +++ b/Tests/testcomm/testaster5.py @@ -20,10 +20,14 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o - if os.path.isfile(f):break + if os.path.isfile(f): + ff=open(f) + text=ff.read() + ff.close() + if text.find("VISU_EFICAS='NON'") == -1: break i=i+1 exec """def test%s(self,file="%s"): self.commtest(file) diff --git a/Tests/testcomm/testaster6.py b/Tests/testcomm/testaster6.py index cb47f3a2..c1c45831 100644 --- a/Tests/testcomm/testaster6.py +++ b/Tests/testcomm/testaster6.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster7.py b/Tests/testcomm/testaster7.py index 5ade9873..df4fab18 100644 --- a/Tests/testcomm/testaster7.py +++ b/Tests/testcomm/testaster7.py @@ -20,10 +20,14 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o - if os.path.isfile(f):break + if os.path.isfile(f): + ff=open(f) + text=ff.read() + ff.close() + if text.find("VISU_EFICAS='NON'") == -1: break i=i+1 exec """def test%s(self,file="%s"): self.commtest(file) diff --git a/Tests/testcomm/testaster8.py b/Tests/testcomm/testaster8.py index 91a04480..8111717b 100644 --- a/Tests/testcomm/testaster8.py +++ b/Tests/testcomm/testaster8.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testcomm/testaster9.py b/Tests/testcomm/testaster9.py index 60841bd2..890a42a1 100644 --- a/Tests/testcomm/testaster9.py +++ b/Tests/testcomm/testaster9.py @@ -20,7 +20,7 @@ class TestCase(unittest.TestCase): ff=open(f) text=ff.read() ff.close() - if text.find("VISU_EFICAS") != -1:continue + if text.find("VISU_EFICAS='NON'") != -1:continue for o in ('3','2','1','0','m'): f=f[:-1]+o if os.path.isfile(f):break diff --git a/Tests/testelem/params.comm b/Tests/testelem/params.comm new file mode 100644 index 00000000..1745633a --- /dev/null +++ b/Tests/testelem/params.comm @@ -0,0 +1,26 @@ + + +DEBUT(); +a = 1.0; + +b = 3; + +c = 15; + +d = 5; + +x = (1, 2); + +y = [3, 4]; + +z = 'a'; + +zz = 'v'; + +t = a; + +v = """aaaa +bbbb"""; + + +FIN(); diff --git a/Tests/testelem/testjdc1.py b/Tests/testelem/testjdc1.py index d904bb65..6f2011f8 100644 --- a/Tests/testelem/testjdc1.py +++ b/Tests/testelem/testjdc1.py @@ -1,6 +1,9 @@ +# coding=utf-8 + import os import unittest import difflib +import compare import prefs from Editeur import appli @@ -153,7 +156,8 @@ FIN(); mcs.set_valeur(mcs.eval_val_item('ACOUSTIQUE')) mcs=mcf[2].get_child("b_acoustique").get_child("MODELISATION") mcs.set_valeur(mcs.eval_val_item('PLAN')) - mcs=add_mcsimp(mcf[2],"GROUP_NO",'GNP3,GNP5,GNP6,GNP7,GNP8,GNP9,GNP10,GNP11,GNP12') + #mcs=add_mcsimp(mcf[2],"GROUP_NO",'GNP3,GNP5,GNP6,GNP7,GNP8,GNP9,GNP10,GNP11,GNP12') + mcs=add_mcsimp(mcf[2],"GROUP_NO","'GNP3','GNP5','GNP6','GNP7','GNP8','GNP9','GNP10','GNP11','GNP12'") co.nomme_sd("AFFE1") # commande AFFE_MODELE @@ -338,15 +342,15 @@ FIN(); mcs=co.get_child("NUME_DDL") mcs.set_valeur_co('DDL1') mcf=co.get_child("MATR_ASSE") + add_mcsimp(mcf[0],"OPTION","RIGI_THER") mcs=mcf[0].get_child("MATRICE") mcs.set_valeur_co('MAT1') - add_mcsimp(mcf[0],"OPTION","RIGI_THER") # commentaire pos=pos+1 co=j.addentite("COMMENTAIRE",pos) co.set_valeur(" 'MACRO_MATR_ASSE', 'MATR_ASSE', 'MATRICE' --> uniquesdcopanel") - assert j.isvalid() + assert j.isvalid(),j.report() text1=app.get_text_JDC(j,'python') file=os.path.join(prefs.INSTALLDIR,"Tests/testelem/az.comm") @@ -354,3 +358,82 @@ FIN(); text2=f.read() f.close() assert text1 == text2 , cdiff(text1,text2) + + def test003(self): + """ Test de construction du fichier de commandes az.comm de zero""" + + app=appli.STANDALONE(version='v8.2') + j=app.newJDC() +# commande DEBUT + co=j.addentite("DEBUT",0) +# commande FIN + co=j.addentite("FIN",1) +#parametre + pos=0 + pos=pos+1 + co=add_param(j,pos,"P1","9.8") + pos=pos+1 + co=add_param(j,pos,"P2","sin(P1)") +# formule + pos=pos+1 + co=j.addentite("FORMULE",pos) + co.update_formule_python(("aaa","REEL","a+z","(a,z)")) +#parametre de formule + pos=pos+1 + co=add_param(j,pos,"P3","aaa(P1,2.)") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","1.,2.,3.") + co.nomme_sd("LI1") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","sin(1.)") + co.nomme_sd("LI2") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","aaa(1.,2.)") + co.nomme_sd("LI3") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","sin(1.,2)") + co.nomme_sd("LI4") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","aaa(1.)") + co.nomme_sd("LI5") +#commande defi_list_reel + pos=pos+1 + co=j.addentite("DEFI_LIST_REEL",pos) + add_mcsimp(co,"VALE","1,sin(1.),2") + co.nomme_sd("LI6") + + expected="""DEBUT CR validation : SansNom + Etape : DEFI_LIST_REEL ligne : ... + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Concept retourné non défini ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Mot-clé simple : VALE + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! 'sin(1.,2)' n'est pas d'un type autorisé ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Fin Mot-clé simple : VALE + Fin Etape : DEFI_LIST_REEL + Etape : DEFI_LIST_REEL ligne : ... + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Concept retourné non défini ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Mot-clé simple : VALE + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! 'aaa(1.)' n'est pas d'un type autorisé ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Fin Mot-clé simple : VALE + Fin Etape : DEFI_LIST_REEL +FIN CR validation :SansNom +""" + msg=str( j.report()) + assert compare.check(expected,msg),cdiff(expected,msg) diff --git a/Tests/testelem/testjdc3.py b/Tests/testelem/testjdc3.py index 8c980e8e..3e6ae647 100644 --- a/Tests/testelem/testjdc3.py +++ b/Tests/testelem/testjdc3.py @@ -1,9 +1,12 @@ +# coding=utf-8 import os import unittest import difflib +import compare import prefs from Editeur import appli +from Accas import AsException def add_param(j,pos,nom,valeur): co=j.addentite("PARAMETRE",pos) @@ -52,3 +55,84 @@ class TestCase(unittest.TestCase): f.close() assert text1 == text2 , cdiff(text1,text2) + def test002(self): + """ Test de commentarisation/decommentarisation de macro commande dans fichier az.comm""" + app=appli.STANDALONE(version='v8.2') + file=os.path.join(prefs.INSTALLDIR,"Tests/testelem/az.comm") + j=app.openJDC(file=file) + assert j.isvalid(),j.report() + # on commente la commande MACRO_MATR_ASSE + for co in j.etapes: + if co.nom == "MACRO_MATR_ASSE" :break + cco=co.get_objet_commentarise(format=app.format_fichier.get()) + # on decommente la commande MACRO_MATR_ASSE + commande,nom = cco.uncomment() + assert j.isvalid(),j.report() + + def test003(self): + """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm""" + app=appli.STANDALONE(version='v8.2') + text=""" +DEBUT() +MA=LIRE_MAILLAGE() +FIN() +""" + j=app.openTXT(text) + assert j.isvalid(),j.report() + # on commente la commande LIRE_MAILLAGE + co=j.etapes[1] + cco=co.get_objet_commentarise(format=app.format_fichier.get()) + co=j.addentite("LIRE_MAILLAGE",2) + test,mess=co.nomme_sd("MA") + # on decommente la commande LIRE_MAILLAGE + commande,nom = cco.uncomment() + expected="""DEBUT CR validation : TEXT + Etape : LIRE_MAILLAGE ligne : ... + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Concept retourné non défini ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Fin Etape : LIRE_MAILLAGE +FIN CR validation :TEXT +""" + msg=str( j.report()) + assert compare.check(expected,msg),cdiff(expected,msg) + + def test004(self): + """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm""" + app=appli.STANDALONE(version='v8.2') + text=""" +DEBUT() +MA=LIRE_MAILLAGE() +AFFE_MODELE(MAILLAGE=MA) +FIN() +""" + j=app.openTXT(text) + # on commente la commande LIRE_MAILLAGE + co=j.etapes[1] + cco=co.get_objet_commentarise(format=app.format_fichier.get()) + # on commente la commande AFFE_MODELE + co=j.etapes[2] + cco2=co.get_objet_commentarise(format=app.format_fichier.get()) + # on decommente la commande AFFE_MODELE + commande,nom = cco2.uncomment() + assert commande["MAILLAGE"] == None + + def test005(self): + """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm""" + app=appli.STANDALONE(version='v8.2') + text=""" +DEBUT() +MA=LIRE_MAILLAGE() +AFFE_MODELE(MAILLAGE=MA) +FIN() +""" + j=app.openTXT(text) + # on commente la commande AFFE_MODELE + co=j.etapes[2] + cco2=co.get_objet_commentarise(format=app.format_fichier.get()) + # on commente la commande LIRE_MAILLAGE + co=j.etapes[1] + cco=co.get_objet_commentarise(format=app.format_fichier.get()) + # on decommente la commande AFFE_MODELE + self.assertRaises(AsException, cco2.uncomment, ) + diff --git a/Tests/testelem/testjdc4.py b/Tests/testelem/testjdc4.py new file mode 100644 index 00000000..8351954a --- /dev/null +++ b/Tests/testelem/testjdc4.py @@ -0,0 +1,56 @@ +# coding=utf-8 +import os +import unittest +import difflib +import compare + +import prefs +from Editeur import appli +from Accas import AsException + +def add_param(j,pos,nom,valeur): + co=j.addentite("PARAMETRE",pos) + co.set_nom(nom) + co.set_valeur(valeur) + return co + +def add_mcsimp(obj,nom,valeur): + mcs=obj.get_child(nom,restreint='oui') + if mcs is None: + pos=obj.get_index_child(nom) + mcs=obj.addentite(nom,pos) + mcs.set_valeur(mcs.eval_val(valeur)) + return mcs + +def cdiff(text1,text2): + return " ".join(difflib.context_diff(text1.splitlines(1),text2.splitlines(1))) + +class TestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + CONTEXT.unset_current_step() + + i=0 + for f in ("params.comm",): + file=os.path.join(prefs.INSTALLDIR,"Tests/testelem",f) + i=i+1 + exec """def test%s(self,file="%s"): + self.commtest(file) +""" % (i,file) + del i + + def commtest(self,file): + """ Test de lecture/ecriture de fichier .comm""" + print file + app=appli.STANDALONE(version='v8.2') + j=app.openJDC(file=file) + assert j.isvalid(),j.report() + + text1=app.get_text_JDC(j,'python') + f=open(file) + text2=f.read() + f.close() + assert text1 == text2 , cdiff(text1,text2) + diff --git a/Tests/testelem/testsimp1.py b/Tests/testelem/testsimp1.py index c6f90a76..25cd7cae 100644 --- a/Tests/testelem/testsimp1.py +++ b/Tests/testelem/testsimp1.py @@ -1,7 +1,9 @@ # coding=utf-8 +import types from Accas import SIMP,ASSD class maillage(ASSD):pass class maillage_sdaster(ASSD):pass +from Accas import ValidException import unittest @@ -241,3 +243,25 @@ Fin Mot-cl self.assertEqual(o.isvalid(),valid, "erreur sur le test %s %s" % (valeur,valid)+'\n'+str(o.report())) if valid: self.assertEqual(o.get_valeur(),valeur) + + def test014(self): + class LongStr: + def __init__(self,min,max): + self.min=min + self.max=max + def __convert__(self,valeur): + if type(valeur) == types.StringType: + if self.min < len(valeur) < self.max:return valeur + return None + + cata=SIMP(typ=LongStr(5,8),statut='o') + liste=(("aaaaaa",1), + ("aaaaaaa",1), + ("aaaaaaaaaaaaaaa",0), + ("aa",0), + ) + for valeur,valid in liste: + o=cata(valeur,'mcs',None) + self.assertEqual(o.isvalid(),valid, + "erreur sur le test %s %s" % (valeur,valid)+'\n'+str(o.report())) + if valid: self.assertEqual(o.get_valeur(),valeur) diff --git a/Tests/testelem/testsimp3.py b/Tests/testelem/testsimp3.py index de100f32..85a10ee4 100644 --- a/Tests/testelem/testsimp3.py +++ b/Tests/testelem/testsimp3.py @@ -52,3 +52,23 @@ class TestSimpCase(unittest.TestCase): #print o.val,o.valeur msg="erreur sur le test %s %s" % (valeur,valid)+'\n'+str(o.report()) self.assertEqual(o.isvalid(),valid,msg=msg) + + def test004(self): + cata=SIMP(typ='C',statut='o',max=10) + liste=((1,1),("a",0), (1.,1),(('RI',1.,0.),1), (('RI',1,0),1), (1+0j,1), + (('RI',Variable('x',1.),0.),1), + (Variable('x',1.),1), + (Variable('x',1.)+0j,1), + ((Variable('x',1.)+0j,1.,0.,Variable('x',1.+2j),Variable('x',Variable('y',1.)+2j)),1), + ("('RI',1,0)",0), ("toto",0), (None,0), + (Variable('x',(1,2,2+5j)),1), + (Variable('x',(1,2,2+5j,5,6,7,8,9,10,11,12)),0), + (Variable('x',(1,2,2+5j,5,6,Variable('y',1+4j),8,9,10,11,12)),0), + (Variable('x',(1,"aaaa",2+5j,5,6,Variable('y',1+4j),8,9,10,11,12)),0), + (1+Variable('x',1.)*1j,1), + ) + for valeur,valid in liste: + o=cata(valeur,'mcs',None) + self.assertEqual(o.isvalid(),valid,"erreur sur le test %s %s" % (valeur,valid)+'\n'+str(o.report())) + if valid: self.assertEqual(o.get_valeur(),valeur) + diff --git a/Tests/testelem/testvalidator2.py b/Tests/testelem/testvalidator2.py index ce843908..a8eb78f0 100644 --- a/Tests/testelem/testvalidator2.py +++ b/Tests/testelem/testvalidator2.py @@ -1,5 +1,6 @@ # coding=utf-8 from Accas import * +from Extensions.param2 import Variable import unittest import compare @@ -48,6 +49,14 @@ Fin Mot-cl ! Mot-clé : mcs devrait avoir longueur de la chaine entre 3 et 5 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Fin Mot-clé simple : mcs +"""), + (Variable('x',"aaa"),OK), + (Variable('x',"aaaaaaaaaaaa"), +"""Mot-clé simple : mcs + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Mot-clé : mcs devrait avoir longueur de la chaine entre 3 et 5 ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +Fin Mot-clé simple : mcs """), ) self._test(cata,liste) @@ -67,6 +76,22 @@ Fin Mot-cl (("aaaa","axyz","bbbb","zzz"),OK), ("aaaa",OK),("aaaaa",OK), ("axyzaa",OK),("bbbbaaa",OK), + (("aaa",Variable('x',"bbb")),OK), + (("aaa",Variable('x',"aaa")), +"""Mot-clé simple : mcs + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Mot-clé : mcs devrait avoir : pas de présence de doublon dans la liste ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +Fin Mot-clé simple : mcs +"""), + (Variable('x',("aaa","bbb")),OK), + (Variable('x',("aaa","bbb","bbb")), +"""Mot-clé simple : mcs + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! Mot-clé : mcs devrait avoir : pas de présence de doublon dans la liste ! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +Fin Mot-clé simple : mcs +"""), ) self._test(cata,liste) -- 2.39.2