source: flex_extract.git/python/testsuite.py @ 991df6a

ctbtodev
Last change on this file since 991df6a was 991df6a, checked in by Anne Philipp <anne.philipp@…>, 6 years ago

finished documentation (except plot_retrieved)

  • Property mode set to 100755
File size: 3.6 KB
Line 
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# ------------------------------------------------------------------------------
39import os
40import sys
41import json
42import subprocess
43
44# ------------------------------------------------------------------------------
45# PROGRAM
46# ------------------------------------------------------------------------------
47try:
48    taskfile = open('testsuite.json')
49except:
50    print 'could not open suite definition file testsuite.json'
51    exit()
52
53if 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
58fprs = os.getenv('FLEXPART_ROOT_SCRIPTS')
59if fprs is None:
60    print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail'
61
62tasks = json.load(taskfile, encoding='latin-1')
63taskfile.close()
64if not os.path.exists('../test'):
65    os.makedirs('../test')
66if len(sys.argv) > 1:
67    groups = sys.argv[1:]
68else:
69    groups = ['xinstall', 'default', 'ops', 'work', 'cv', 'fc']#,'hires']
70jobcounter = 0
71jobfailed = 0
72for 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
110print 'Test suite tasks completed'
111print str(jobcounter-jobfailed) + ' successful, ' + str(jobfailed) + ' failed'
112print 'If tasks have been submitted via ECACCESS please check emails'
113
114#print tasks
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG