source: flex_extract.git/Source/Pythontest/TestInput.py @ 76c37a9

ctbtodev
Last change on this file since 76c37a9 was 76c37a9, checked in by Anne Philipp <anne.philipp@…>, 4 years ago

updated unit tests to work with updated code

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