source: flex_extract.git/python/test_suite.py @ e1228f3

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

completed application of pep8 style guide and pylint investigations. added documentation almost everywhere

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