2 # Copyright (C) 2006-2020 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
30 dir_test = tempfile.mkdtemp(suffix=".yacstest")
32 class TestDeco(unittest.TestCase):
35 SALOMERuntime.RuntimeSALOME_setRuntime()
40 jdd -> foreach -> post
46 expected_1, expected_2 = testforeach.main()
47 yacs_schema_file = os.path.join(dir_test, "schema_t1.xml")
48 yacs_build_command = "yacsbuild.py"
49 test_script = "testforeach.py"
50 main_function_name = "main"
51 subprocess.run([yacs_build_command,
52 test_script, main_function_name, yacs_schema_file])
53 l = loader.YACSLoader()
54 ex = pilot.ExecutorSwig()
55 proc = l.load(yacs_schema_file)
57 obtained_1 = proc.getChildByName("post_0").getOutputPort("s").getPyObj()
58 obtained_2 = proc.getChildByName("f1_1").getOutputPort("r").getPyObj()
59 self.assertEqual(expected_1, obtained_1)
60 self.assertEqual(expected_2, obtained_2)
64 Foreach initialized by value.
67 expected_1, expected_2 = testforeach.mainbloc()
68 yacs_schema_file = os.path.join(dir_test, "schema_t2.xml")
69 yacs_build_command = "yacsbuild.py"
70 test_script = "testforeach.py"
71 main_function_name = "mainbloc"
72 subprocess.run([yacs_build_command,
73 test_script, main_function_name, yacs_schema_file])
74 l = loader.YACSLoader()
75 ex = pilot.ExecutorSwig()
76 proc = l.load(yacs_schema_file)
78 obtained_1 = proc.getChildByName("output_fr_0").getOutputPort("s_0").getPyObj()
79 obtained_2 = proc.getChildByName("output_fr_0").getOutputPort("p_1").getPyObj()
80 self.assertEqual(expected_1, obtained_1)
81 self.assertEqual(expected_2, obtained_2)
88 expected = testforeach.maindoublefr()
89 yacs_schema_file = os.path.join(dir_test, "schema_t3.xml")
90 yacs_build_command = "yacsbuild.py"
91 test_script = "testforeach.py"
92 main_function_name = "maindoublefr"
93 subprocess.run([yacs_build_command,
94 test_script, main_function_name, yacs_schema_file])
95 l = loader.YACSLoader()
96 ex = pilot.ExecutorSwig()
97 proc = l.load(yacs_schema_file)
99 obtained = proc.getChildByName("output_doublefr_0").getOutputPort("r_0_0").getPyObj()
100 self.assertEqual(expected, obtained)
104 Using specific containers.
107 cm = yacsdecorator.ContainerManager()
108 cm.addContainer("c1", 1, False)
109 cm.addContainer("c2", 4, True)
110 cm.addContainer(yacsdecorator.ContainerManager.defaultContainerName, 1, False)
111 cont_file = os.path.join(dir_test, "containers_t4.json")
112 cm.saveFile(cont_file)
113 script = """import yacsdecorator
114 @yacsdecorator.leaf("c1")
119 @yacsdecorator.leaf("c2")
135 script_file = os.path.join(dir_test, "script_t4.py")
136 with open(script_file, "w") as f:
138 yacs_build_command = "yacsbuild.py"
139 main_function_name = "main"
140 yacs_schema_file = os.path.join(dir_test, "schema_t4.xml")
141 subprocess.run([yacs_build_command,
142 script_file, main_function_name, yacs_schema_file,
144 l = loader.YACSLoader()
145 ex = pilot.ExecutorSwig()
146 proc = l.load(yacs_schema_file)
148 self.assertEqual(proc.getState(),pilot.DONE)
149 c1 = proc.getChildByName("f_c1_0").getContainer()
150 self.assertFalse(c1.isUsingPythonCache())
151 self.assertEqual(c1.getProperty("nb_parallel_procs"), "1")
152 c2 = proc.getChildByName("f_c2_0").getContainer()
153 self.assertTrue(c2.isUsingPythonCache())
154 self.assertEqual(c2.getProperty("nb_parallel_procs"), "4")
155 c3 = proc.getChildByName("f_def_0").getContainer()
156 self.assertFalse(c3.isUsingPythonCache())
157 self.assertEqual(c3.getProperty("nb_parallel_procs"), "1")
159 if __name__ == '__main__':
160 file_test = os.path.join(dir_test,"UnitTestsResult")
161 with open(file_test, 'a') as f:
162 f.write(" --- TEST src/py2yacs: testDeco.py\n")
163 suite = unittest.makeSuite(TestDeco)
164 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
165 sys.exit(not result.wasSuccessful())