Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / yacsloader / Test / testLoader.py
1 #  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 #
3 #  This library is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU Lesser General Public
5 #  License as published by the Free Software Foundation; either
6 #  version 2.1 of the License.
7 #
8 #  This library is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 #  Lesser General Public License for more details.
12 #
13 #  You should have received a copy of the GNU Lesser General Public
14 #  License along with this library; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 import pilot
20 import SALOMERuntime
21 import loader
22 import unittest
23
24 class TestLoader(unittest.TestCase):
25
26   def setUp(self):
27     SALOMERuntime.RuntimeSALOME_setRuntime()
28     self.r = pilot.getRuntime()
29     self.l = loader.YACSLoader()
30     self.e = pilot.ExecutorSwig()
31     pass
32
33   def tearDown(self):
34     del self.r
35     del self.l
36     del self.e
37
38   def test1_FileNotExist(self):
39     # --- File does not exist
40     retex=None
41     try:
42       p = self.l.load("nonexisting")
43     except IOError, ex:
44       print "IO Error: ", ex
45       retex=ex
46     #except pilot.invalid_argument,ex:
47     #  print "invalid_argument:",ex.what()
48     #  retex=ex.what()
49     self.assert_(retex is not None, "exception not raised, or wrong type")
50     pass
51
52   def test2_parseError(self):
53     # --- File exists but parse error
54     retex=None
55     try:
56       p = self.l.load("samples/bid.xml")
57     except ValueError,ex:
58       print "Caught ValueError Exception:",ex
59       retex = ex
60     expected="LogRecord: parser:ERROR:from node node5 does not exist in control link: node5->b2 context: b1. (samples/bid.xml:53)\n"
61     self.assert_(p.getLogger("parser").getStr() == expected, "error not found: "+p.getLogger("parser").getStr())
62     pass
63
64   def test3_normal(self):
65     # --- File exists and no parsing problem
66     try:
67       p = self.l.load("samples/aschema.xml")
68       print p.getLogger("parser").getStr()
69       print p
70       print p.getName()
71       for k in p.typeMap: print k
72       for k in p.nodeMap: print k
73       for k in p.inlineMap: print k
74       for k in p.serviceMap: print k
75       print self.e.getTasksToLoad()
76       self.e.RunW(p,0)
77       self.assertEqual(106, p.getChildByName('node48').getEffectiveState())
78     except pilot.Exception,ex:
79       print "YACS exception:",ex
80       self.fail(ex)
81       pass
82     pass
83
84 import os
85 U = os.getenv('USER')
86 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
87 f.write("  --- TEST src/yacsloader: testLoader.py\n")
88 suite = unittest.makeSuite(TestLoader)
89 unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
90 f.close()