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