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

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

added pathes in config file and according testcases

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