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
RevLine 
[d69b677]1#!/usr/bin/env python
[991df6a]2# -*- coding: utf-8 -*-
3#************************************************************************
[ff99eae]4# ToDo AP
[991df6a]5# - provide more tests
6# - provide more documentation
7#************************************************************************
[d69b677]8
[991df6a]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
[64cf353]19#
[991df6a]20# @License:
21#    (C) Copyright 2015-2018.
[d69b677]22#
[991df6a]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.
[64cf353]25#
[991df6a]26# @Program Functionality:
27#    This script triggers the ECMWFDATA test suite. Call with
[ff99eae]28#    test_suite.py [test group]
[d69b677]29#
[991df6a]30# @Program Content:
[64cf353]31#
[991df6a]32#*******************************************************************************
[d69b677]33
[991df6a]34# ------------------------------------------------------------------------------
35# MODULES
36# ------------------------------------------------------------------------------
37import os
38import sys
[d69b677]39import json
40import subprocess
[64cf353]41
[991df6a]42# ------------------------------------------------------------------------------
43# PROGRAM
44# ------------------------------------------------------------------------------
[d69b677]45try:
[ff99eae]46    taskfile = open('test_suite.json')
47except IOError:
48    print 'could not open suite definition file test_suite.json'
[d69b677]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
[991df6a]56fprs = os.getenv('FLEXPART_ROOT_SCRIPTS')
[d69b677]57if fprs is None:
58    print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail'
59
[991df6a]60tasks = json.load(taskfile, encoding='latin-1')
[d69b677]61taskfile.close()
62if not os.path.exists('../test'):
63    os.makedirs('../test')
[991df6a]64if len(sys.argv) > 1:
65    groups = sys.argv[1:]
[d69b677]66else:
[991df6a]67    groups = ['xinstall', 'default', 'ops', 'work', 'cv', 'fc']#,'hires']
68jobcounter = 0
69jobfailed = 0
[d69b677]70for g in groups:
71    try:
[991df6a]72        tk, tv = g, tasks[g]
[ff99eae]73    finally:
74        pass
[991df6a]75    garglist = []
76    for ttk, ttv in tv.iteritems():
77        if isinstance(ttv, basestring):
78            if ttk != 'script':
79                garglist.append('--' + ttk)
[ff99eae]80                if ttv[0] == '$':
[d69b677]81                    garglist.append(os.path.expandvars(ttv))
82                else:
83                    garglist.append(ttv)
[991df6a]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):
[ff99eae]89                    arglist.append('--' + tttk)
90                    if '$' in tttv[0]:
91                        arglist.append(os.path.expandvars(tttv))
92                    else:
93                        arglist.append(tttv)
[991df6a]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')
[d69b677]98            try:
[991df6a]99                p = subprocess.check_call([tv['script']] + garglist + arglist,
100                                          stdout=f, stderr=f)
[ff99eae]101            except subprocess.CalledProcessError as e:
[d69b677]102                f.write('\nFAILED\n')
103                print 'FAILED'
[991df6a]104                jobfailed += 1
105            jobcounter += 1
[d69b677]106            f.close()
107
108print 'Test suite tasks completed'
[991df6a]109print str(jobcounter-jobfailed) + ' successful, ' + str(jobfailed) + ' failed'
[d69b677]110print 'If tasks have been submitted via ECACCESS please check emails'
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG