1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | #************************************************************************ |
---|
4 | # TODO AP |
---|
5 | # |
---|
6 | # - provide more tests |
---|
7 | # - provide more documentation |
---|
8 | # - |
---|
9 | #************************************************************************ |
---|
10 | |
---|
11 | #******************************************************************************* |
---|
12 | # @Author: Leopold Haimberger (University of Vienna) |
---|
13 | # |
---|
14 | # @Date: December 2015 |
---|
15 | # |
---|
16 | # @Change History: |
---|
17 | # |
---|
18 | # February 2018 - Anne Philipp (University of Vienna): |
---|
19 | # - applied PEP8 style guide |
---|
20 | # - added documentation |
---|
21 | # |
---|
22 | # @License: |
---|
23 | # (C) Copyright 2015-2018. |
---|
24 | # |
---|
25 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
26 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
27 | # |
---|
28 | # @Program Functionality: |
---|
29 | # This script triggers the ECMWFDATA test suite. Call with |
---|
30 | # testsuite.py [test group] |
---|
31 | # |
---|
32 | # @Program Content: |
---|
33 | # |
---|
34 | #******************************************************************************* |
---|
35 | |
---|
36 | # ------------------------------------------------------------------------------ |
---|
37 | # MODULES |
---|
38 | # ------------------------------------------------------------------------------ |
---|
39 | import os |
---|
40 | import sys |
---|
41 | import json |
---|
42 | import subprocess |
---|
43 | |
---|
44 | # ------------------------------------------------------------------------------ |
---|
45 | # PROGRAM |
---|
46 | # ------------------------------------------------------------------------------ |
---|
47 | try: |
---|
48 | taskfile = open('testsuite.json') |
---|
49 | except: |
---|
50 | print 'could not open suite definition file testsuite.json' |
---|
51 | exit() |
---|
52 | |
---|
53 | if not os.path.isfile('../src/CONVERT2'): |
---|
54 | print '../src/CONVERT2 could not be found' |
---|
55 | print 'please run "install.py --target=local" first' |
---|
56 | exit() |
---|
57 | |
---|
58 | fprs = os.getenv('FLEXPART_ROOT_SCRIPTS') |
---|
59 | if fprs is None: |
---|
60 | print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail' |
---|
61 | |
---|
62 | tasks = json.load(taskfile, encoding='latin-1') |
---|
63 | taskfile.close() |
---|
64 | if not os.path.exists('../test'): |
---|
65 | os.makedirs('../test') |
---|
66 | if len(sys.argv) > 1: |
---|
67 | groups = sys.argv[1:] |
---|
68 | else: |
---|
69 | groups = ['xinstall', 'default', 'ops', 'work', 'cv', 'fc']#,'hires'] |
---|
70 | jobcounter = 0 |
---|
71 | jobfailed = 0 |
---|
72 | for g in groups: |
---|
73 | try: |
---|
74 | tk, tv = g, tasks[g] |
---|
75 | except: |
---|
76 | continue |
---|
77 | garglist = [] |
---|
78 | for ttk, ttv in tv.iteritems(): |
---|
79 | if isinstance(ttv, basestring): |
---|
80 | if ttk != 'script': |
---|
81 | garglist.append('--' + ttk) |
---|
82 | if '$' == ttv[0]: |
---|
83 | garglist.append(os.path.expandvars(ttv)) |
---|
84 | else: |
---|
85 | garglist.append(ttv) |
---|
86 | for ttk, ttv in tv.iteritems(): |
---|
87 | if isinstance(ttv, dict): |
---|
88 | arglist = [] |
---|
89 | for tttk, tttv in ttv.iteritems(): |
---|
90 | if isinstance(tttv, basestring): |
---|
91 | arglist.append('--' + tttk) |
---|
92 | if '$' in tttv[0]: |
---|
93 | arglist.append(os.path.expandvars(tttv)) |
---|
94 | else: |
---|
95 | arglist.append(tttv) |
---|
96 | print 'Command: ', ' '.join([tv['script']] + garglist + arglist) |
---|
97 | o = '../test/' + tk + '_' + ttk + '_' + '_'.join(ttv.keys()) |
---|
98 | print 'Output will be sent to ', o |
---|
99 | f = open(o, 'w') |
---|
100 | try: |
---|
101 | p = subprocess.check_call([tv['script']] + garglist + arglist, |
---|
102 | stdout=f, stderr=f) |
---|
103 | except: |
---|
104 | f.write('\nFAILED\n') |
---|
105 | print 'FAILED' |
---|
106 | jobfailed += 1 |
---|
107 | jobcounter += 1 |
---|
108 | f.close() |
---|
109 | |
---|
110 | print 'Test suite tasks completed' |
---|
111 | print str(jobcounter-jobfailed) + ' successful, ' + str(jobfailed) + ' failed' |
---|
112 | print 'If tasks have been submitted via ECACCESS please check emails' |
---|
113 | |
---|
114 | #print tasks |
---|