Salome HOME
CCAR: merge de la version 1.14 dans la branche principale
[tools/eficas.git] / Tests / testelem / testitem1.py
1 import os
2 import unittest
3 import difflib
4
5 import prefs
6 from InterfaceTK import appli
7 #from Editeur import appli
8 from Editeur import comploader
9 from Editeur import Objecttreeitem
10
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    """ Tests sur des items """
33    def setUp(self):
34       pass
35
36    def tearDown(self):
37       CONTEXT.unset_current_step()
38
39    def test001(self):
40       """Test comploader"""
41       composants=comploader.charger_composants()
42       itemtype=comploader.gettreeitem({'a':1})
43       assert itemtype is Objecttreeitem.ObjectTreeItem
44
45    def test002(self):
46       """ Test de commentarisation/decommentarisation a partir d'un item jdc """
47       app=appli.STANDALONE(version=version)
48       file=os.path.join(prefs.INSTALLDIR,"Tests/testelem/az.comm")
49       j=app.openJDC(file=file)
50       item=app.create_item(j)
51       assert item.isvalid(),item.report()
52       # on commente la commande LIRE_MAILLAGE
53       commands=item.GetSubList()
54       for it in commands:
55         if it.nom == "LIRE_MAILLAGE" and it.sd.nom == "MAIL":break
56       pos=commands.index(it)
57       cco=it.get_objet_commentarise()
58       commands=item.GetSubList()
59       commands[pos].uncomment()
60       commands=item.GetSubList()
61       # on reaffecte l'objet MAIL
62       for it in commands:
63         if it.nom in ("AFFE_MODELE","AFFE_MATERIAU") :
64            for mc in it.GetSubList():
65               if mc.nom == "MAILLAGE":
66                  valeur,validite=mc.eval_valeur("MAIL")
67                  test = mc.set_valeur(valeur)
68       text1=app.get_text_JDC(j,'python')
69       f=open(file)
70       text2=f.read()
71       f.close()
72       assert text1 == text2 , cdiff(text1,text2)
73