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