source: flex_extract.git/python/pythontest/TestInput.py @ f9f7b3f

ctbtodev
Last change on this file since f9f7b3f was 067a0c3, checked in by Anne Philipp <anne.philipp@…>, 6 years ago

renamed documentation dir; moved pythontest to python dir

  • Property mode set to 100644
File size: 5.8 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import unittest
5import os
6import sys
7sys.path.append('../python')
8from ControlFile import ControlFile
9import tools
10
11
12class TestInput(unittest.TestCase):
13    '''
14    Test class to test the reading of commandline arguments and
15    control file.
16    '''
17    # ToDo
18    # create more tests for input
19    # 1. nur controlfile reading
20    # 2. check of parameter
21
22    def setUp(self):
23        '''
24        '''
25        # Default values for ArgumentParser
26        self.args = {'start_date':None,
27                     'end_date':None,
28                     'date_chunk':None,
29                     'basetime':None,
30                     'step':None,
31                     'levelist':None,
32                     'area':None,
33                     'inputdir':None,
34                     'outputdir':None,
35                     'flexpart_root_scripts':None,
36                     'ppid':None,
37                     'job_template':'job.temp',
38                     'queue':None,
39                     'controlfile':'CONTROL.temp',
40                     'debug':0,
41                     }
42        #sys.argv = ['dummy.py', '--start_date=20180101', '--debug=1',
43        #            '--step=0/to/11/BY/3', '--area=20./20./0./90.']
44        sys.argv = ['dummy.py', '--start_date=20180101']
45
46        self.args = tools.get_commandline_arguments()
47
48        self.c = ControlFile('TestData/CONTROL.temp')
49
50        self.c.assign_args_to_control(self.args)
51
52        self.c.check_conditions()
53
54        return
55
56    def test_args_reading(self):
57
58        sys.argv = ['dummy.py', '--start_date=20180101', '--debug=1',
59                    '--step=0/to/11/BY/3', '--area=20./20./0./90.']
60
61        arguments = tools.get_commandline_arguments()
62
63        args_exp = {'start_date':'20180101',
64                    'end_date':None,
65                    'date_chunk':None,
66                    'basetime':None,
67                    'step':'0/to/11/BY/3',
68                    'levelist':None,
69                    'area':'20./20./0./90.',
70                    'inputdir':None,
71                    'outputdir':None,
72                    'flexpart_root_scripts':None,
73                    'ppid':None,
74                    'job_template':'job.temp',
75                    'queue':None,
76                    'controlfile':'CONTROL.temp',
77                    'debug':1,
78                    }
79
80        self.assertDictEqual(vars(arguments), args_exp)
81        return
82
83    def test_args_assignment(self):
84
85        import collections
86
87        # expected parametervalue:
88        exp_dict = {
89                    'accuracy': '16',
90                    'addpar': ['186', '187', '188', '235', '139', '39'],
91                    'area': None,
92                    'basetime': None,
93                    'controlfile': 'CONTROL.temp',
94                    'cwc': 0,
95                    'date_chunk': 3,
96                    'debug': 0,
97                    'destination': None,
98                    'dpdeta': '1',
99                    'dtime': '3',
100                    'ecfsdir': 'ectmp:/${USER}/econdemand/',
101                    'ecgid': None,
102                    'ecmwfdatadir': '/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/../',
103                    'ecstorage': '0',
104                    'ectrans': '1',
105                    'ecuid': None,
106                    'end_date': '20180101',
107                    'eta': '0',
108                    'etadiff': '0',
109                    'etapar': 77,
110                    'exedir': '/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/../src/',
111                    'expver': '1',
112                    'flexpart_root_scripts': '/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/../',
113                    'format': 'GRIB1',
114                    'gateway': None,
115                    'gauss': '1',
116                    'grib2flexpart': '0',
117                    'grid': '5000',
118                    'inputdir': '../work',
119                    'job_template': 'job.temp',
120                    'left': '-15000',
121                    'level': '60',
122                    'levelist': '55/to/60',
123                    'lower': '30000',
124                    'mailfail': ['${USER}'],
125                    'mailops': ['${USER}'],
126                    'makefile': None,
127                    'marsclass': 'EI',
128                    'maxstep': 11,
129                    'number': 'OFF',
130                    'omega': '0',
131                    'omegadiff': '0',
132                    'outputdir': '../work',
133                    'prefix': 'EI',
134                    'resol': '63',
135                    'right': '45000',
136                    'smooth': '0',
137                    'start_date': '20180101',
138                    'step': ['00', '01', '02', '03', '04', '05', '00', '07', '08', '09', '10', '11', '00', '01', '02', '03', '04', '05', '00', '07', '08', '09', '10', '11'],
139                    'stream': 'OPER',
140                    'target': None,
141                    'time': ['00', '00', '00', '00', '00', '00', '06', '00', '00', '00', '00', '00', '12', '12', '12', '12', '12', '12', '18', '12', '12', '12', '12', '12'],
142                    'type': ['AN', 'FC', 'FC', 'FC', 'FC', 'FC', 'AN', 'FC', 'FC', 'FC', 'FC', 'FC', 'AN', 'FC', 'FC', 'FC', 'FC', 'FC', 'AN', 'FC', 'FC', 'FC', 'FC', 'FC'],
143                    'upper': '75000',
144                    'wrf': 0}
145
146        exp_dict = collections.OrderedDict(sorted(exp_dict.items()))
147        cdict = collections.OrderedDict(sorted(vars(self.c).items()))
148
149        # remove content which isn't comparable for different users
150        # or different operating systems
151        del cdict['ecfsdir_expanded']
152        del cdict['mailops_expanded']
153        del cdict['mailfail_expanded']
154
155        #print 'cdict\n', cdict
156        #print 'exp_dict\n', exp_dict
157
158        #assert cdict == exp_dict
159        self.assertDictEqual(cdict, exp_dict)
160
161        return
162
163if __name__ == "__main__":
164    unittest.main()
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG