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)
102 if __name__ == '__main__':
103 file_test = os.path.join(dir_test,"UnitTestsResult")
104 with open(file_test, 'a') as f:
105 f.write(" --- TEST src/py2yacs: testDeco.py\n")
106 suite = unittest.makeSuite(TestDeco)
107 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
108 sys.exit(not result.wasSuccessful())