Salome HOME
216976b3d17bc354f4a853ead2e5fd4879336fb8
[modules/yacs.git] / src / yacsloader_swig / Test / testFixes.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2006-2024  CEA, EDF
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 """
22 Various non regression tests.
23 """
24
25 import sys
26 import pilot
27 import SALOMERuntime
28 import loader
29 import unittest
30 import tempfile
31 import os
32 import salome
33
34 NB_NODE=15
35 class TestEdit(unittest.TestCase):
36
37     def setUp(self):
38         SALOMERuntime.RuntimeSALOME_setRuntime()
39         self.r = pilot.getRuntime()
40         self.l = loader.YACSLoader()
41         self.e = pilot.ExecutorSwig()
42         # We need a catalog which contains only one resource named "localhost"
43         # with NB_NODE cores. The modifications made here are not saved to the
44         # catalog file.
45         salome.salome_init()
46         resourceManager = salome.lcc.getResourcesManager()
47         resource_definition = resourceManager.GetResourceDefinition("localhost")
48         resource_definition.nb_node = NB_NODE
49         resource_definition.nb_proc_per_node = 1
50         resourceManager.AddResource(resource_definition, False, "")
51         resource_required = salome.ResourceParameters()
52         resource_required.can_run_containers = True
53         res_list = resourceManager.GetFittingResources(resource_required)
54         for r in res_list:
55           if r != "localhost":
56             resourceManager.RemoveResource(r, False, "")
57         resource_definition = resourceManager.GetResourceDefinition("localhost")
58         self.assertEqual(resource_definition.nb_node, NB_NODE)
59         self.assertEqual(resource_definition.nb_proc_per_node, 1)
60
61     def tearDown(self):
62         cm = salome.lcc.getContainerManager()
63         cm.ShutdownContainers()
64
65     def test_double_foreach_switch(self):
66         """ Two layers of nested foreach and switch structures.
67         """
68         proc = self.l.load("samples/foreach_switch_double.xml")
69         self.e.RunW(proc,0)
70         self.assertEqual(proc.getState(),pilot.DONE)
71         ok = proc.getChildByName("End").getOutputPort("ok")
72         self.assertTrue(ok, "Wrong result!")
73
74 if __name__ == '__main__':
75   dir_test = tempfile.mkdtemp(suffix=".yacstest")
76   file_test = os.path.join(dir_test,"UnitTestsResult")
77   with open(file_test, 'a') as f:
78       f.write("  --- TEST src/yacsloader: testFixes.py\n")
79       suite = unittest.makeSuite(TestEdit)
80       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
81   sys.exit(not result.wasSuccessful())