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