Salome HOME
CCAR:ajout d'un repertoire de tests elementaires
[tools/eficas.git] / Tests / testelem / testjdc2.py
1 # -*- coding: iso-8859-1 -*-
2 import cata5
3
4 import unittest,re,os
5 import compare
6
7 class TestJDCCase(unittest.TestCase):
8
9    def test1(self):
10       text="""
11 # OP2 : CO converti en concept2 ou concept2. Retourne concept
12 # OP6 : uniquement CO converti en concept2. Retourne concept
13 # OP3 : CO converti en concept ou concept. Retourne concept
14 co0=OP2(MATR=CO("x1"))
15 co2=OP6(MATR=CO("xx"))
16 co3=OP3(MATR={"CHAM":"R","MM":co2})
17 """
18       self.execute(cata5,text)
19
20    def test2(self):
21       text="""
22 # OP2 : CO converti en concept2 ou concept2. Retourne concept
23 # OP5 : uniquement CO converti en concept2. Retourne concept
24 co0=OP2(MATR=CO("x1"))
25 co1=OP5(MATR=co0)
26 """
27       expected="""DEBUT CR validation : bidon
28    Etape : OP5    ligne : 5    fichier : 'bidon'
29       Mot-clé simple : MATR
30          !!!!!!...
31          ! ... n'est pas d'un type autorisé !
32          !!!!!!...
33       Fin Mot-clé simple : MATR
34    Fin Etape : OP5
35 FIN CR validation :bidon
36 """
37       self.execute(cata5,text,err3=expected)
38
39    def test3(self):
40       text="""
41 # OP2 : CO converti en concept2 ou concept2. Retourne concept
42 co0=OP2(MATR=CO("x1"))
43 co1=OP2(MATR=x1)
44 co2=OP2(MATR=co0)
45 """
46       expected="""DEBUT CR validation : bidon
47    Etape : OP2    ligne : 5    fichier : 'bidon'
48       Mot-clé simple : MATR
49          !!!!...
50          ! ... n'est pas d'un type autorisé !
51          !!!!...
52       Fin Mot-clé simple : MATR
53    Fin Etape : OP2
54 FIN CR validation :bidon
55 """
56       self.execute(cata5,text,err3=expected)
57
58    def test8(self):
59       text="""
60 co2=OP14(MATR=CO("xx"))
61 """
62       expected=""
63       self.execute(cata5,text,err4=expected)
64
65    def test12(self):
66       text="""
67 co2=OP18(MATR=CO("xx"))
68 co3=OP2(MATR=xx)
69 co4=OP11(MATR=xx)
70 """
71       expected=""
72       self.execute(cata5,text,err4=expected)
73
74    def test13(self):
75       text="""
76 co2=OP10(MATR=CO("xx"))
77 """
78       expected="""DEBUT CR validation : bidon
79    Etape : OP10    ligne : 2    fichier : 'bidon'
80       Mot-clé simple : MATR
81          !!!!...
82          ! ... n'est pas d'un type autorisé !
83          !!!!...
84       Fin Mot-clé simple : MATR
85    Fin Etape : OP10
86 FIN CR validation :bidon
87 """
88       self.execute(cata5,text,err3=expected)
89
90    def test16(self):
91       text="""
92 co=OP22(MATR=CO("xx"))
93 """
94       self.execute(cata5,text)
95
96    def test17(self):
97       text="""
98 co=OP22(MATR=CO("xx"))
99 co2=OP22(MATR=xx)
100 """
101       expected="""DEBUT CR validation : bidon
102    Etape : OP22    ligne : 3    fichier : 'bidon'
103       Mot-clé simple : MATR
104          !!!!!!!!...
105          ! ... n'est pas d'un type autorisé !
106          !!!!!!!...
107       Fin Mot-clé simple : MATR
108    Fin Etape : OP22
109 FIN CR validation :bidon
110 """
111       self.execute(cata5,text,err3=expected)
112
113    def setUp(self):
114       pass
115
116    def tearDown(self):
117       pass
118
119    def execute(self,cata,text_jdc,err1="",err2="",err3="",err4=""):
120       j=cata.JdC(procedure=text_jdc,cata=cata,nom="bidon")
121       j.actif_status=1
122       j.fico=None
123       j.set_par_lot("OUI")
124       # On compile le texte Python
125       j.compile()
126       # On initialise les tops de mesure globale de temps d'execution du jdc
127       j.cpu_user=os.times()[0]
128       j.cpu_syst=os.times()[1]
129       j.impr_macro='NON'
130
131       #print j.cr
132       if err1 == "":
133         self.assert_(j.cr.estvide(),msg='Erreur non attendue dans compile (err1):\n%s' % str(j.cr))
134       else:
135         self.assert_(self.check(err1,str(j.cr)),msg='Erreur non attendue dans compile (err1):\n%s\n!=\n%s' % (str(j.cr),err1))
136         j.supprime()
137         return
138
139       j.exec_compile()
140       #print j.cr
141       if err2 == "":
142         self.assert_(j.cr.estvide(),msg='Erreur non attendue dans exec_compile (err2):\n%s' % str(j.cr))
143       else:
144         self.assert_(self.check(err2,str(j.cr)),msg='Erreur non attendue dans exec_compile(err2):\n%s\n!=\n%s' % (str(j.cr),err2))
145         j.supprime()
146         return
147
148       cr=j.report()
149       #print cr
150       if err3 == "":
151         self.assert_(cr.estvide(),msg='Erreur non attendue dans exec_compile (err3):\n%s' % str(cr))
152       else:
153         self.assert_(self.check(err3,str(cr)),msg='Erreur non attendue dans exec_compile(err3):\n%s\n!=\n%s' % (str(cr),err3))
154         j.supprime()
155         return
156
157       j.set_par_lot("NON")
158
159       j.supprime()
160
161    def check(self,want,got):
162       return compare.check(want,got)