68b14b86c8441519e416e8cb517187a0fe10b6bb
[qpalma.git] / tests / test_qpalma_installation.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # Written (W) 2008 Fabio De Bona
10 # Copyright (C) 2008 Max-Planck-Society
11
12 #
13 # This file performs a lot of checks in order to verify the installation of
14 # QPalma
15 #
16
17 import os
18 import sys
19 import unittest
20
21 from test_approximation import TestApproximation
22 from test_qpalma import TestQPalmaPrediction
23 from test_utils import TestSequenceUtils
24
25 SUCCESS = True
26
27 def check_for_module(module_name):
28
29 try:
30 exec("import %s"%module_name)
31 except:
32 return False
33 sys.exc_info()
34
35 return True
36
37
38 if __name__ == '__main__':
39
40
41
42 log_fn = 'error.log'
43
44 if os.path.exists(log_fn):
45 os.remove(log_fn)
46
47 out_fh = open(log_fn,'w+')
48
49 print '\nChecking if your installation was successful...'
50
51 print '\nChecking for needed modules...\n'
52
53
54 module_list = ['numpy','DRMAA','Genefinding','pythongrid','QPalmaDP','qpalma']
55
56 for mod in module_list:
57 status = check_for_module(mod)
58 if status:
59 mes = "Successful!"
60 else:
61 mes = "Failed!"
62 SUCCESS = False
63
64 line = 'Status of module %s:\t%s'%(mod,mes)
65 print line
66 out_fh.write(line+'\n')
67
68 print '\nChecking for optional modules...\n'
69
70 module_list = ['pycplex', 'cvxopt', 'pymosek']
71
72 for mod in module_list:
73 line = 'Status of module %s:\t%s'%(mod,str(check_for_module(mod)))
74 print line
75 out_fh.write(line+'\n')
76
77 # after checking the modules we run some simple testcases on QPalma.
78 data_suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceUtils)
79 approximation_suite = unittest.TestLoader().loadTestsFromTestCase(TestApproximation)
80 prediction_suite = unittest.TestLoader().loadTestsFromTestCase(TestQPalmaPrediction)
81
82 all_suites = unittest.TestSuite([data_suite, approximation_suite, prediction_suite])
83 test_result = unittest.TextTestRunner(verbosity=2).run(all_suites)
84 test_status = test_result.wasSuccessful()
85
86 print 'TEST STATUS is %s' % str(test_status)
87
88 if SUCCESS and test_status:
89 print '\n\n--- All checks where successful!! ---\n\n'
90 else:
91 print '\n\n--- Send the file error.log to qpalma@tuebingen.mpg.de ---\n\n'
92 env = os.environ
93 lines = ''
94 for var in ['PATH','LD_LIBRARY_PATH','PYTHONPATH']:
95 lines += '%s=%s\n'%(var,env[var])
96 out_fh.write(lines)
97
98 out_fh.close()