Salome HOME
Small fix for Python3
[tools/yacsgen.git] / Examples / test_compo.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # This test executes the coupling.xml schema found in the current directory
4 # and verifies the execution state.
5 import unittest
6
7 import os
8 import sys
9
10 import imp
11 appli_dir = "appli"
12 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
13 salome_module = imp.load_source("SALOME", os.path.join(appli_dir, "salome"))
14
15 class TestCompo(unittest.TestCase):
16   def setUp(self):
17     #start salome and connect to it
18     try:
19       salome_module.main(["start", "-t"])
20     except SystemExit as e:
21       pass
22     import runSession
23     runSession.configureSession()
24     import setenv
25     setenv.main(True)
26     
27     # creat study and load catalogs
28     import SALOMERuntime
29     SALOMERuntime.RuntimeSALOME_setRuntime()
30     salome_runtime = SALOMERuntime.getSALOMERuntime()
31     
32     import salome
33     salome.salome_init()
34     
35     mc = salome.naming_service.Resolve('/Kernel/ModulCatalog')
36     ior = salome.orb.object_to_string(mc)
37     session_catalog = salome_runtime.loadCatalog("session", ior)
38     salome_runtime.addCatalog(session_catalog)
39
40   def test_exec_scheme(self):
41     import pilot
42     import loader
43
44     xmlLoader = loader.YACSLoader()
45     try:
46       p = xmlLoader.load("coupling.xml")
47     except IOError as ex:
48       self.fail("IO exception:" + ex);
49     self.assertTrue(p.isValid())
50     e = pilot.ExecutorSwig()
51     e.RunW(p)
52     self.assertEqual(p.getEffectiveState(), pilot.DONE)
53     
54   def tearDown(self):
55     try:
56       salome_module.main(["killall"])
57     except SystemExit as e:
58       pass
59   
60 if __name__ == '__main__':
61     unittest.main()