source: flex_extract.git/python/test_suite.py @ 97e09f4

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

restructuring, documentations and bug fixes

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