[7025] | 1 | #!/bin/env python |
---|
| 2 | |
---|
| 3 | '''Testlet to run the EQRM 'test_all.py' script.''' |
---|
| 4 | |
---|
| 5 | import os |
---|
| 6 | import time |
---|
| 7 | import test_utils as util |
---|
| 8 | |
---|
| 9 | name = 'Running EQRM test_all.py' |
---|
| 10 | |
---|
| 11 | def test(logfile): |
---|
| 12 | result = True |
---|
| 13 | |
---|
| 14 | (cluster, domain) = util.get_hostname() |
---|
| 15 | |
---|
| 16 | # get python to run |
---|
| 17 | python_env_var = os.getenv('PYTHON') |
---|
| 18 | |
---|
| 19 | # remember the directory we are in and go to EQRM test directory |
---|
| 20 | home_directory = os.getcwd() |
---|
| 21 | eqrm_path = os.getenv('EQRMPATH') |
---|
| 22 | if not eqrm_path: |
---|
| 23 | util.log_print_nl(logfile, "The EQRMPATH environment variable not set, " |
---|
| 24 | "can't test EQRM.") |
---|
| 25 | return False |
---|
| 26 | |
---|
| 27 | os.chdir(os.path.join(eqrm_path)) |
---|
[7079] | 28 | print 'in %s' % os.getcwd() |
---|
[7025] | 29 | |
---|
[7079] | 30 | # run clean_all.py |
---|
| 31 | util.log_print_nl(logfile, '%s clean_all.py' % python_env_var) |
---|
| 32 | (fd_in, fd_out) = os.popen4('%s clean_all.py' % python_env_var) |
---|
| 33 | fd_in.write('y\n') |
---|
| 34 | fd_in.close() |
---|
| 35 | clean_result = fd_out.read() |
---|
| 36 | fd_out.close() |
---|
| 37 | util.log_print(logfile, clean_result) |
---|
| 38 | |
---|
[7025] | 39 | # run test_all.py |
---|
| 40 | util.log_print_nl(logfile, '%s test_all.py' % python_env_var) |
---|
[7079] | 41 | (_, fd_out) = os.popen4('%s test_all.py' % python_env_var) |
---|
| 42 | test_result = fd_out.read() |
---|
| 43 | status = fd_out.close() |
---|
[7025] | 44 | util.log_print(logfile, test_result) |
---|
| 45 | |
---|
| 46 | # return to original directory |
---|
| 47 | os.chdir(home_directory) |
---|
| 48 | |
---|
| 49 | return result |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | if __name__ == '__main__': |
---|
| 53 | import sys |
---|
| 54 | |
---|
| 55 | home_directory = os.getcwd() |
---|
| 56 | logfile = os.path.join(home_directory, 'test.log') |
---|
| 57 | if len(sys.argv) > 1: |
---|
| 58 | logfile = sys.argv[1] |
---|
| 59 | |
---|
| 60 | try: |
---|
| 61 | os.remove(logfile) |
---|
| 62 | except: |
---|
| 63 | pass |
---|
| 64 | |
---|
| 65 | if not test(logfile): |
---|
| 66 | sys.exit(10) |
---|
| 67 | |
---|
| 68 | sys.exit(0) |
---|