2 # -*- coding: utf-8 -*-
5 This script prepares the test environment and runs a test script:
6 - clean and create test directory
7 - create a SALOME application
9 - launch the test script within SALOME environment
12 This script uses the following environment variables:
13 - ROOT_SALOME : directory which contains salome_context.cfg.
14 This variable is usually defined in salome_prerequisites.sh
15 - KERNEL_ROOT_DIR and YACS_ROOT_DIR : directories of modules installation
16 Those variables are usually defined in salome_modules.sh
17 Environment variables can be passed to the script using the -d option.
23 class TestEnvironment:
26 shutil.rmtree("appli", ignore_errors=True)
28 # create config_appli.xml in current directory
29 salome_path = os.getenv("ROOT_SALOME", "")
30 salome_context_file = os.path.join(salome_path, "salome_context.cfg")
31 if not os.path.isfile(salome_context_file):
32 print "File salome_context.cfg not found."
33 print "Search path:" + salome_path
34 print "This test needs ROOT_SALOME environment variable in order to run"
37 config_appli_text = '''<application>
38 <context path="''' + salome_context_file + '''"/>
40 <module name="KERNEL" path="'''
41 kernel_path = os.getenv("KERNEL_ROOT_DIR", "")
42 if not os.path.isdir(kernel_path) :
43 print "KERNEL_ROOT_DIR not defined"
47 config_appli_text += kernel_path + '"/>'
49 # some tests need YACS module.
50 yacs_path = os.getenv("YACS_ROOT_DIR", "")
51 if os.path.isdir(yacs_path):
52 config_appli_text += '''
53 <module name="YACS" path="'''
54 config_appli_text += yacs_path + '"/>'
56 config_appli_text += '''
60 f = open("config_appli.xml", 'w')
61 f.write(config_appli_text)
64 # create a SALOME application
65 appli_gen_file = os.path.join(kernel_path,
66 "bin","salome","appli_gen.py")
68 os.system(appli_gen_file + " --prefix="+appli_dir+
69 " --config=config_appli.xml")
73 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
74 self.salome_module = imp.load_source("SALOME", os.path.join(appli_dir, "salome"))
76 self.salome_module.main(["start", "-t"])
78 # There is an exit() call in salome.main. Just ignore it.
81 def run(self, script):
84 ret = self.salome_module.main(["shell", script])
92 self.salome_module.main(["killall"])
96 pass #class TestEnvironment
98 if __name__ == '__main__':
100 parser = argparse.ArgumentParser(description=usage,
101 formatter_class=argparse.RawDescriptionHelpFormatter)
102 parser.add_argument('command', help="Test command to be run.")
103 parser.add_argument('-d', '--define', action='append', help="VARIABLE=VALUE")
105 args = parser.parse_args()
106 for opt in args.define:
107 opts = opt.split('=', 1)
108 os.environ[opts[0]] = opts[1]
110 envTest = TestEnvironment()
112 ret = envTest.run(args.command)