]> SALOME platform Git repositories - tools/eficas.git/blob - Tests/testelem/testjdc3.py
Salome HOME
CCAR: merge de la branche de développement V1_11a1 dans la branche
[tools/eficas.git] / Tests / testelem / testjdc3.py
1 # coding=utf-8
2 import os
3 import unittest
4 import difflib
5 import compare
6
7 import prefs
8 from Editeur import appli
9 from Accas import AsException
10
11 def add_param(j,pos,nom,valeur):
12     co=j.addentite("PARAMETRE",pos)
13     co.set_nom(nom)
14     co.set_valeur(valeur)
15     return co
16
17 def add_mcsimp(obj,nom,valeur):
18     mcs=obj.get_child(nom,restreint='oui')
19     if mcs is None:
20        pos=obj.get_index_child(nom)
21        mcs=obj.addentite(nom,pos)
22     mcs.set_valeur(mcs.eval_val(valeur))
23     return mcs
24
25 def cdiff(text1,text2):
26     return " ".join(difflib.context_diff(text1.splitlines(1),text2.splitlines(1)))
27
28 version='v8'
29
30 class TestCase(unittest.TestCase):
31    def setUp(self):
32       pass
33
34    def tearDown(self):
35       CONTEXT.unset_current_step()
36
37    def test001(self):
38       """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
39       app=appli.STANDALONE(version=version)
40       file=os.path.join(prefs.INSTALLDIR,"Tests/testelem/az.comm")
41       j=app.openJDC(file=file)
42       assert j.isvalid(),j.report()
43       # on commente la commande LIRE_MAILLAGE
44       for co in j.etapes:
45         if co.nom == "LIRE_MAILLAGE" and co.sd.nom == "MAIL":break
46       cco=co.get_objet_commentarise(format=app.format_fichier.get())
47       # on decommente la commande LIRE_MAILLAGE
48       commande,nom = cco.uncomment()
49       # on reaffecte l'objet MAIL
50       for co in j.etapes:
51         if co.nom in ("AFFE_MODELE","AFFE_MATERIAU") :
52            add_mcsimp(co,"MAILLAGE",'MAIL')
53
54       text1=app.get_text_JDC(j,'python')
55       f=open(file)
56       text2=f.read()
57       f.close()
58       assert text1 == text2 , cdiff(text1,text2)
59
60    def test002(self):
61       """ Test de commentarisation/decommentarisation de macro commande dans fichier az.comm"""
62       app=appli.STANDALONE(version=version)
63       file=os.path.join(prefs.INSTALLDIR,"Tests/testelem/az.comm")
64       j=app.openJDC(file=file)
65       assert j.isvalid(),j.report()
66       # on commente la commande MACRO_MATR_ASSE
67       for co in j.etapes:
68         if co.nom == "MACRO_MATR_ASSE" :break
69       cco=co.get_objet_commentarise(format=app.format_fichier.get())
70       # on decommente la commande MACRO_MATR_ASSE
71       commande,nom = cco.uncomment()
72       assert j.isvalid(),j.report()
73
74    def test003(self):
75       """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
76       app=appli.STANDALONE(version=version)
77       text="""
78 DEBUT()
79 MA=LIRE_MAILLAGE()
80 FIN()
81 """
82       j=app.openTXT(text)
83       assert j.isvalid(),j.report()
84       # on commente la commande LIRE_MAILLAGE
85       co=j.etapes[1]
86       cco=co.get_objet_commentarise(format=app.format_fichier.get())
87       co=j.addentite("LIRE_MAILLAGE",2)
88       test,mess=co.nomme_sd("MA")
89       # on decommente la commande LIRE_MAILLAGE
90       commande,nom = cco.uncomment()
91       expected="""DEBUT CR validation : TEXT
92    Etape : LIRE_MAILLAGE    ligne : ...
93       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94       ! Concept retourné non défini !
95       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
96    Fin Etape : LIRE_MAILLAGE
97 FIN CR validation :TEXT
98 """
99       msg=str( j.report())
100       assert compare.check(expected,msg),cdiff(expected,msg)
101
102    def test004(self):
103       """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
104       app=appli.STANDALONE(version=version)
105       text="""
106 DEBUT()
107 MA=LIRE_MAILLAGE()
108 AFFE_MODELE(MAILLAGE=MA)
109 FIN()
110 """
111       j=app.openTXT(text)
112       # on commente la commande LIRE_MAILLAGE
113       co=j.etapes[1]
114       cco=co.get_objet_commentarise(format=app.format_fichier.get())
115       # on commente la commande AFFE_MODELE
116       co=j.etapes[2]
117       cco2=co.get_objet_commentarise(format=app.format_fichier.get())
118       # on decommente la commande AFFE_MODELE
119       commande,nom = cco2.uncomment()
120       assert commande["MAILLAGE"] == None
121
122    def test005(self):
123       """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
124       app=appli.STANDALONE(version=version)
125       text="""
126 DEBUT()
127 MA=LIRE_MAILLAGE()
128 AFFE_MODELE(MAILLAGE=MA)
129 FIN()
130 """
131       j=app.openTXT(text)
132       # on commente la commande AFFE_MODELE
133       co=j.etapes[2]
134       cco2=co.get_objet_commentarise(format=app.format_fichier.get())
135       # on commente la commande LIRE_MAILLAGE
136       co=j.etapes[1]
137       cco=co.get_objet_commentarise(format=app.format_fichier.get())
138       # on decommente la commande AFFE_MODELE
139       self.assertRaises(AsException, cco2.uncomment, )
140