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):
53 config_appli_text += '''
54 <module name="YACS" path="'''
55 config_appli_text += yacs_path + '"/>'
57 config_appli_text += '''
61 f = open("config_appli.xml", 'w')
62 f.write(config_appli_text)
65 # create a SALOME application
66 appli_gen_file = os.path.join(kernel_path,
67 "bin","salome","appli_gen.py")
69 os.system(appli_gen_file + " --prefix="+appli_dir+
70 " --config=config_appli.xml")
74 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
75 self.salome_module = imp.load_source("SALOME", os.path.join(appli_dir, "salome"))
77 self.salome_module.main(["start", "-t"])
79 # There is an exit() call in salome.main. Just ignore it.
82 def run(self, script):
85 ret = self.salome_module.main(["shell", script])
93 self.salome_module.main(["killall"])
97 pass #class TestEnvironment
99 if __name__ == '__main__':
101 parser = argparse.ArgumentParser(description=usage,
102 formatter_class=argparse.RawDescriptionHelpFormatter)
103 parser.add_argument('command', help="Test command to be run.")
104 parser.add_argument('-d', '--define', action='append', help="VARIABLE=VALUE")
106 args = parser.parse_args()
107 for opt in args.define:
108 opts = opt.split('=', 1)
109 os.environ[opts[0]] = opts[1]
111 envTest = TestEnvironment()
113 ret = envTest.run(args.command)