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