[2fb99de] | 1 | #!/usr/bin/env python |
---|
| 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 |
---|
| 13 | # |
---|
| 14 | # @License: |
---|
| 15 | # (C) Copyright 2015-2018. |
---|
| 16 | # |
---|
| 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. |
---|
| 19 | # |
---|
| 20 | # @Program Functionality: |
---|
| 21 | # This script triggers the flex_extract test suite. Call with |
---|
| 22 | # test_suite.py [test group] |
---|
| 23 | # |
---|
| 24 | # @Program Content: |
---|
| 25 | # |
---|
| 26 | #******************************************************************************* |
---|
| 27 | |
---|
| 28 | # ------------------------------------------------------------------------------ |
---|
| 29 | # MODULES |
---|
| 30 | # ------------------------------------------------------------------------------ |
---|
| 31 | import os |
---|
| 32 | import sys |
---|
| 33 | import json |
---|
| 34 | import subprocess |
---|
| 35 | |
---|
| 36 | # ------------------------------------------------------------------------------ |
---|
| 37 | # PROGRAM |
---|
| 38 | # ------------------------------------------------------------------------------ |
---|
| 39 | try: |
---|
| 40 | taskfile = open('test_suite.json') |
---|
| 41 | except IOError: |
---|
| 42 | print 'could not open suite definition file test_suite.json' |
---|
| 43 | exit() |
---|
| 44 | |
---|
| 45 | if 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 | |
---|
| 50 | fprs = os.getenv('FLEXPART_ROOT_SCRIPTS') |
---|
| 51 | if fprs is None: |
---|
| 52 | print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail' |
---|
| 53 | |
---|
| 54 | tasks = json.load(taskfile, encoding='latin-1') |
---|
| 55 | taskfile.close() |
---|
| 56 | if not os.path.exists('../test'): |
---|
| 57 | os.makedirs('../test') |
---|
| 58 | if len(sys.argv) > 1: |
---|
| 59 | groups = sys.argv[1:] |
---|
| 60 | else: |
---|
| 61 | groups = ['xinstall', 'default', 'ops', 'work', 'cv', 'fc']#,'hires'] |
---|
| 62 | jobcounter = 0 |
---|
| 63 | jobfailed = 0 |
---|
| 64 | for g in groups: |
---|
| 65 | try: |
---|
| 66 | tk, tv = g, tasks[g] |
---|
| 67 | finally: |
---|
| 68 | pass |
---|
| 69 | garglist = [] |
---|
| 70 | for ttk, ttv in tv.iteritems(): |
---|
| 71 | if isinstance(ttv, basestring): |
---|
| 72 | if ttk != 'script': |
---|
| 73 | garglist.append('--' + ttk) |
---|
| 74 | if ttv[0] == '$': |
---|
| 75 | garglist.append(os.path.expandvars(ttv)) |
---|
| 76 | else: |
---|
| 77 | garglist.append(ttv) |
---|
| 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): |
---|
| 83 | arglist.append('--' + tttk) |
---|
| 84 | if '$' in tttv[0]: |
---|
| 85 | arglist.append(os.path.expandvars(tttv)) |
---|
| 86 | else: |
---|
| 87 | arglist.append(tttv) |
---|
| 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') |
---|
| 92 | try: |
---|
| 93 | p = subprocess.check_call([tv['script']] + garglist + arglist, |
---|
| 94 | stdout=f, stderr=f) |
---|
| 95 | except subprocess.CalledProcessError as e: |
---|
| 96 | f.write('\nFAILED\n') |
---|
| 97 | print 'FAILED' |
---|
| 98 | jobfailed += 1 |
---|
| 99 | jobcounter += 1 |
---|
| 100 | f.close() |
---|
| 101 | |
---|
| 102 | print 'Test suite tasks completed' |
---|
| 103 | print str(jobcounter-jobfailed) + ' successful, ' + str(jobfailed) + ' failed' |
---|
| 104 | print 'If tasks have been submitted via ECACCESS please check emails' |
---|