2 # Copyright (C) 2006-2022 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 class TestLoader(unittest.TestCase):
29 SALOMERuntime.RuntimeSALOME_setRuntime()
30 self.r = pilot.getRuntime()
31 self.l = loader.YACSLoader()
32 self.e = pilot.ExecutorSwig()
40 def test1_FileNotExist(self):
41 # --- File does not exist
44 p = self.l.load("nonexisting")
46 print("IO Error: ", ex)
48 # except pilot.invalid_argument as ex:
49 # print("invalid_argument:",str(ex))
51 self.assertTrue(retex is not None, "exception not raised, or wrong type")
54 def test2_parseError(self):
55 # --- File exists but parse error
58 p = self.l.load("samples/bid.xml")
59 except ValueError as ex:
60 print("Caught ValueError Exception:",ex)
62 expected="LogRecord: parser:ERROR:from node node5 does not exist in control link: node5->b2 context: b1. (samples/bid.xml:53)\n"
63 self.assertTrue(p.getLogger("parser").getStr() == expected, "error not found: "+p.getLogger("parser").getStr())
66 def test3_normal(self):
67 # --- File exists and no parsing problem
69 p = self.l.load("samples/aschema.xml")
70 print(p.getLogger("parser").getStr())
73 for k in p.typeMap: print(k)
74 for k in p.nodeMap: print(k)
75 for k in p.inlineMap: print(k)
76 for k in p.serviceMap: print(k)
77 print(self.e.getTasksToLoad())
79 self.assertEqual(106, p.getChildByName('node48').getEffectiveState())
80 except pilot.Exception as ex:
81 print("YACS exception:",ex)
86 if __name__ == '__main__':
89 dir_test = tempfile.mkdtemp(suffix=".yacstest")
90 file_test = os.path.join(dir_test,"UnitTestsResult")
91 with open(file_test, 'a') as f:
92 f.write(" --- TEST src/yacsloader: testLoader.py\n")
93 suite = unittest.makeSuite(TestLoader)
94 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
95 sys.exit(not result.wasSuccessful())