Salome HOME
ca2b8086fce5b13cf856af7c4bd898e432ba8f33
[modules/yacs.git] / src / yacsloader_swig / Test / testLoader.py
1 # Copyright (C) 2006-2019  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, or (at your option) any later version.
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
20 import pilot
21 import SALOMERuntime
22 import loader
23 import unittest
24
25 class TestLoader(unittest.TestCase):
26
27   def setUp(self):
28     SALOMERuntime.RuntimeSALOME_setRuntime()
29     self.r = pilot.getRuntime()
30     self.l = loader.YACSLoader()
31     self.e = pilot.ExecutorSwig()
32     pass
33
34   def tearDown(self):
35     del self.r
36     del self.l
37     del self.e
38
39   def test1_FileNotExist(self):
40     # --- File does not exist
41     retex=None
42     try:
43       p = self.l.load("nonexisting")
44     except IOError as ex:
45       print("IO Error: ", ex)
46       retex=ex
47     # except pilot.invalid_argument as ex:
48     #  print("invalid_argument:",str(ex))
49     #  retex=ex.what()
50     self.assertTrue(retex is not None, "exception not raised, or wrong type")
51     pass
52
53   def test2_parseError(self):
54     # --- File exists but parse error
55     retex=None
56     try:
57       p = self.l.load("samples/bid.xml")
58     except ValueError as ex:
59       print("Caught ValueError Exception:",ex)
60       retex = ex
61     expected="LogRecord: parser:ERROR:from node node5 does not exist in control link: node5->b2 context: b1. (samples/bid.xml:53)\n"
62     self.assertTrue(p.getLogger("parser").getStr() == expected, "error not found: "+p.getLogger("parser").getStr())
63     pass
64
65   def test3_normal(self):
66     # --- File exists and no parsing problem
67     try:
68       p = self.l.load("samples/aschema.xml")
69       print(p.getLogger("parser").getStr())
70       print(p)
71       print(p.getName())
72       for k in p.typeMap: print(k)
73       for k in p.nodeMap: print(k)
74       for k in p.inlineMap: print(k)
75       for k in p.serviceMap: print(k)
76       print(self.e.getTasksToLoad())
77       self.e.RunW(p,0)
78       self.assertEqual(106, p.getChildByName('node48').getEffectiveState())
79     except pilot.Exception as ex:
80       print("YACS exception:",ex)
81       self.fail(ex)
82       pass
83     pass
84
85 if __name__ == '__main__':
86   import os
87   U = os.getenv('USER')
88   with open("/tmp/" + U + "/UnitTestsResult", 'a') as f:
89       f.write("  --- TEST src/yacsloader: testLoader.py\n")
90       suite = unittest.makeSuite(TestLoader)
91       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
92   sys.exit(not result.wasSuccessful())