2 from Accas import SIMP,FACT,BLOC,UN_PARMI,OPER,ASSD,MACRO,_F
8 CONTEXT.unset_current_cata()
9 CONTEXT.set_current_cata(self)
10 def enregistre(self,cmd):
15 class concept(ASSD):pass
17 OP1 = OPER(nom='OP1',op=1, sd_prod=concept,
18 WWWW=SIMP(statut='o',typ='TXM', position='global'),
19 XXXX=SIMP(typ='TXM', position='global',defaut='XXXX'),
20 traitement=FACT(statut='o',
21 TATA=SIMP(typ='TXM', position='global',defaut='DDD'),
22 TTTT=SIMP(statut='o',typ='TXM', position='global',defaut='EEE'),
23 UUUU=SIMP(typ='TXM', position='global'),
24 VVVV=SIMP(statut='o',typ='TXM', position='global'),
25 regles=( UN_PARMI('TYPE_RAFFINEMENT_LIBRE','TYPE_RAFFINEMENT_UNIFORME'),),
26 TYPE_RAFFINEMENT_LIBRE = FACT(statut='f',
27 RAFFINEMENT = SIMP(statut='o',typ='TXM', position='global',
28 into=("LIBRE","UNIFORME",) ),
29 DERAFFINEMENT = SIMP(statut='o',typ='TXM', position='global',
31 TOTO=SIMP(statut='o',typ='TXM', position='global'),
32 # un mot cle global facultatif ne sera pas visible tant
33 # qu'il n'aura pas de valeur meme s'il a un defaut
34 TITI=SIMP(typ='TXM', position='global',defaut='BBB'),
35 TUTU=SIMP(statut='o',typ='TXM', position='global',defaut='CCC'),
37 b_maj_champ =BLOC(condition="(RAFFINEMENT!=None) or (DERAFFINEMENT!=None)",
38 NITER =SIMP(statut='o',typ='I',),
39 NOM_MED_MAILLAGE_NP1 =SIMP(statut='o',typ='TXM',),
40 FICHIER_MED_MAILLAGE_NP1 =SIMP(statut='o',typ='TXM',),
43 trait=FACT(statut='o',
44 FFFF=SIMP(typ='TXM',),
45 b_champ =BLOC(condition="WWWW=='WWWW'",
46 N =SIMP(statut='o',typ='I',),
51 MACR_BIDON=OPER(nom="MACR_BIDON",op=None,sd_prod=concept,
52 reentrant='n',UIinfo={"groupes":("Outils métier",)},fr="",
53 NOM_CHAM=SIMP(statut='f',typ='TXM',into=('ACCE','DEPL'),position="global"),
54 RESULTAT=FACT(statut='o',b_acce=BLOC(condition="NOM_CHAM=='ACCE'",
55 VAL1=SIMP(statut='o',typ='R'),
57 VAL2=SIMP(statut='o',typ='R'),
62 class TestMCBlocCase(unittest.TestCase):
65 """ bloc conditionnel declenche par mot cle global avec defaut
67 mcf={'TYPE_RAFFINEMENT_LIBRE':{'TOTO':'AAA'}}
68 co=OP1(traitement=mcf,WWWW='WWWW')
69 mcfact=co.etape['traitement']
70 self.assertEqual(mcfact['TYPE_RAFFINEMENT_LIBRE']['DERAFFINEMENT'] , None)
71 dico=mcfact[0].cree_dict_valeurs(mcfact[0].mc_liste)
72 self.assertEqual(dico['DERAFFINEMENT'] , None)
73 self.assertEqual(dico['RAFFINEMENT'] , None)
74 self.assertEqual(dico['WWWW'] , 'WWWW')
75 self.assertRaises(IndexError, mcfact.__getitem__, 'NITER')
77 mcfact=co.etape['trait'][0]
78 dico=mcfact.cree_dict_valeurs(mcfact.mc_liste)
79 self.assertEqual(dico['DERAFFINEMENT'] , None)
80 self.assertEqual(dico['RAFFINEMENT'] , None)
81 self.assertEqual(dico['WWWW'] , 'WWWW')
82 self.assertEqual(dico['TOTO'] , 'AAA')
83 self.assertEqual(dico['TUTU'] , 'CCC')
84 self.assertEqual(dico['FFFF'] , None)
85 self.assertEqual(dico['VVVV'] , None)
86 self.assertEqual(dico['TTTT'] , 'EEE')
87 self.assertEqual(dico['XXXX'] , 'XXXX')
88 self.assertEqual(mcfact['N'] , None)
89 self.assertRaises(KeyError, dico.__getitem__, 'TITI')
92 mcf={'TYPE_RAFFINEMENT_LIBRE':{'RAFFINEMENT':'LIBRE'},'NITER':1}
93 co=OP1(traitement=mcf)
94 mcfact=co.etape['traitement']
95 self.assertEqual(mcfact['TYPE_RAFFINEMENT_LIBRE']['RAFFINEMENT'] , 'LIBRE')
96 self.assertEqual(mcfact['NITER'] , 1)
99 co=MACR_BIDON(NOM_CHAM='ACCE',RESULTAT=_F(VAL2=3.4))
100 mcfact=co.etape['RESULTAT']
101 self.assertEqual(co.etape.isvalid(), 0)
105 'TYPE_RAFFINEMENT_LIBRE':{'RAFFINEMENT':'LIBRE','DERAFFINEMENT':'LIBRE','TOTO':'AA'},
107 'FICHIER_MED_MAILLAGE_NP1':'',
108 'NOM_MED_MAILLAGE_NP1':'',
110 co=OP1(traitement=mcf,WWWW="WWWW",trait={'N':1})
111 val=co.etape.isvalid()
112 if not val:msg=co.etape.report()
114 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
116 co=OP1(traitement=mcf,WWWW="WWWW")
117 val=co.etape.isvalid()
118 if not val:msg=co.etape.report()
120 self.assertEqual(co.etape.isvalid() , 0,msg=msg)
122 co=OP1(traitement=mcf,WWWW="WW",trait={'N':1})
123 val=co.etape.isvalid()
124 if not val:msg=co.etape.report()
126 self.assertEqual(co.etape.isvalid() , 0,msg=msg)
128 co=OP1(traitement=mcf,WWWW="WW",trait={'FFFF':'X'})
129 val=co.etape.isvalid()
130 if not val:msg=co.etape.report()
132 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
134 co=OP1(traitement=mcf,WWWW="WW",)
135 val=co.etape.isvalid()
136 if not val:msg=co.etape.report()
138 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
141 OP1 = OPER(nom='OP1',op=1, sd_prod=concept,
142 MASS = FACT(statut='f',max='**',
143 Y = SIMP(statut='f',typ='I',),
144 Z = FACT(T=SIMP(typ='I')),
146 b_mass = BLOC(condition = "MASS != None",
147 MODE = SIMP(statut='o',typ='I',)
149 bb_mass = BLOC(condition = "MASS and len(MASS) > 1 ",
150 XX = SIMP(statut='o',typ='I',)
152 bbb_mass = BLOC(condition = "MASS and MASS[0]['Y'] == 1 ",
153 YY = SIMP(statut='o',typ='I',)
155 bbbb_mass = BLOC(condition = "MASS and MASS[0]['Z'] and MASS[0]['Z'][0]['T'] == 1 ",
156 ZZ = SIMP(statut='o',typ='I',)
160 msg=co.etape.report()
161 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
162 co=OP1(MASS={},MODE=1)
163 msg=co.etape.report()
164 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
165 co=OP1(MASS=({},{}),MODE=1,XX=1)
166 msg=co.etape.report()
167 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
168 co=OP1(MASS=({'Y':1},{}),MODE=1,XX=1,YY=1)
169 msg=co.etape.report()
170 self.assertEqual(co.etape.isvalid() , 1,msg=msg)
171 co=OP1(MASS=({'Y':1,'Z':{'T':1}},{}),MODE=1,XX=1,YY=1,ZZ=1)
172 msg=co.etape.report()
173 self.assertEqual(co.etape.isvalid() , 1,msg=msg)