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