8 from Editeur import appli
9 from Accas import AsException
11 def add_param(j,pos,nom,valeur):
12 co=j.addentite("PARAMETRE",pos)
17 def add_mcsimp(obj,nom,valeur):
18 mcs=obj.get_child(nom,restreint='oui')
20 pos=obj.get_index_child(nom)
21 mcs=obj.addentite(nom,pos)
22 mcs.set_valeur(mcs.eval_val(valeur))
25 def cdiff(text1,text2):
26 return " ".join(difflib.context_diff(text1.splitlines(1),text2.splitlines(1)))
30 class TestCase(unittest.TestCase):
35 CONTEXT.unset_current_step()
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
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
51 if co.nom in ("AFFE_MODELE","AFFE_MATERIAU") :
52 add_mcsimp(co,"MAILLAGE",'MAIL')
54 text1=app.get_text_JDC(j,'python')
58 assert text1 == text2 , cdiff(text1,text2)
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
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()
75 """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
76 app=appli.STANDALONE(version=version)
83 assert j.isvalid(),j.report()
84 # on commente la commande LIRE_MAILLAGE
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
100 assert compare.check(expected,msg),cdiff(expected,msg)
103 """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
104 app=appli.STANDALONE(version=version)
108 AFFE_MODELE(MAILLAGE=MA)
112 # on commente la commande LIRE_MAILLAGE
114 cco=co.get_objet_commentarise(format=app.format_fichier.get())
115 # on commente la commande AFFE_MODELE
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
123 """ Test de commentarisation/decommentarisation de commandes dans fichier az.comm"""
124 app=appli.STANDALONE(version=version)
128 AFFE_MODELE(MAILLAGE=MA)
132 # on commente la commande AFFE_MODELE
134 cco2=co.get_objet_commentarise(format=app.format_fichier.get())
135 # on commente la commande LIRE_MAILLAGE
137 cco=co.get_objet_commentarise(format=app.format_fichier.get())
138 # on decommente la commande AFFE_MODELE
139 self.assertRaises(AsException, cco2.uncomment, )