Commit d637c5c30fc0cc979bd91232b4eaf8bf67846684

Authored by Luigi Tibaldo
1 parent 02262b17

removed emprty lines

Showing 1 changed file with 4 additions and 210 deletions
test/test_python_cscripts.py
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 -  
3 # ========================================================================== 2 # ==========================================================================
4 -  
5 # This scripts performs unit tests for cscripts 3 # This scripts performs unit tests for cscripts
6 -  
7 # 4 #
8 -  
9 # Copyright (C) 2016-2019 Juergen Knoedlseder 5 # Copyright (C) 2016-2019 Juergen Knoedlseder
10 -  
11 # 6 #
12 -  
13 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
14 -  
15 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
16 -  
17 # the Free Software Foundation, either version 3 of the License, or 9 # the Free Software Foundation, either version 3 of the License, or
18 -  
19 # (at your option) any later version. 10 # (at your option) any later version.
20 -  
21 # 11 #
22 -  
23 # This program is distributed in the hope that it will be useful, 12 # This program is distributed in the hope that it will be useful,
24 -  
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 -  
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 -  
29 # GNU General Public License for more details. 15 # GNU General Public License for more details.
30 -  
31 # 16 #
32 -  
33 # You should have received a copy of the GNU General Public License 17 # You should have received a copy of the GNU General Public License
34 -  
35 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
36 -  
37 # 19 #
38 -  
39 # ========================================================================== 20 # ==========================================================================
40 21
  22 +import cscripts
  23 +import gammalib
41 import os 24 import os
42 -  
43 import sys 25 import sys
44 26
45 -import gammalib  
46 -  
47 -import cscripts  
48 -  
49 sys.path.append(os.path.dirname(os.path.abspath(__file__))) 27 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
50 28
51 import test_cscript 29 import test_cscript
52 -  
53 import test_cscaldb 30 import test_cscaldb
54 -  
55 import test_csbkgmodel 31 import test_csbkgmodel
56 -  
57 import test_csebins 32 import test_csebins
58 -  
59 import test_csfindobs 33 import test_csfindobs
60 -  
61 import test_csinfo 34 import test_csinfo
62 -  
63 import test_cslightcrv 35 import test_cslightcrv
64 -  
65 import test_csmodelinfo 36 import test_csmodelinfo
66 -  
67 import test_csmodelmerge 37 import test_csmodelmerge
68 -  
69 import test_csmodelselect 38 import test_csmodelselect
70 -  
71 import test_csmodelsois 39 import test_csmodelsois
72 -  
73 import test_csobs2caldb 40 import test_csobs2caldb
74 -  
75 import test_csobsdef 41 import test_csobsdef
76 -  
77 import test_csobsinfo 42 import test_csobsinfo
78 -  
79 import test_csobsselect 43 import test_csobsselect
80 -  
81 import test_csphagen 44 import test_csphagen
82 -  
83 import test_csphasecrv 45 import test_csphasecrv
84 -  
85 import test_cspull 46 import test_cspull
86 -  
87 import test_csresmap 47 import test_csresmap
88 -  
89 import test_csresspec 48 import test_csresspec
90 -  
91 import test_csroot2caldb 49 import test_csroot2caldb
92 -  
93 import test_cssens 50 import test_cssens
94 -  
95 import test_csspec 51 import test_csspec
96 -  
97 import test_cssrcdetect 52 import test_cssrcdetect
98 -  
99 import test_cstsdist 53 import test_cstsdist
100 -  
101 import test_cstsmapmerge 54 import test_cstsmapmerge
102 -  
103 import test_cstsmapsplit 55 import test_cstsmapsplit
104 -  
105 import test_csviscube 56 import test_csviscube
106 -  
107 import test_csscs 57 import test_csscs
108 import test_csworkflow 58 import test_csworkflow
109 -  
110 import test_obsutils 59 import test_obsutils
111 -  
112 import test_mputils 60 import test_mputils
113 -  
114 import test_csiactcopy 61 import test_csiactcopy
115 -  
116 import test_csiactdata 62 import test_csiactdata
117 -  
118 import test_csiactobs 63 import test_csiactobs
119 64
120 65
121 -  
122 -  
123 -  
124 # ================== # 66 # ================== #
125 67
126 # Perform unit tests # 68 # Perform unit tests #
@@ -128,286 +70,142 @@ import test_csiactobs @@ -128,286 +70,142 @@ import test_csiactobs
128 # ================== # 70 # ================== #
129 71
130 def test(installed=False, debug=False): 72 def test(installed=False, debug=False):
131 -  
132 """ 73 """
133 -  
134 Perform cscripts unit testing. 74 Perform cscripts unit testing.
135 75
136 -  
137 -  
138 Parameters 76 Parameters
139 -  
140 ---------- 77 ----------
141 -  
142 installed : bool, optional 78 installed : bool, optional
143 -  
144 Flag indicating whether the script has been installed or not 79 Flag indicating whether the script has been installed or not
145 -  
146 debug : bool, optional 80 debug : bool, optional
147 -  
148 Enables debugging 81 Enables debugging
149 -  
150 """ 82 """
151 83
152 # If we have an installed version then create a temporary directory and 84 # If we have an installed version then create a temporary directory and
153 -  
154 # copy over all information that is needed 85 # copy over all information that is needed
155 -  
156 if installed: 86 if installed:
157 -  
158 -  
159 -  
160 # Create temporary working directory 87 # Create temporary working directory
161 -  
162 import tempfile 88 import tempfile
163 -  
164 path = tempfile.mkdtemp() 89 path = tempfile.mkdtemp()
165 -  
166 os.chdir(path) 90 os.chdir(path)
167 -  
168 -  
169 -  
170 # Get test directory 91 # Get test directory
171 -  
172 import inspect 92 import inspect
173 -  
174 testdir = inspect.getfile(cscripts.tests) 93 testdir = inspect.getfile(cscripts.tests)
175 -  
176 dirname = os.path.dirname(testdir) 94 dirname = os.path.dirname(testdir)
177 -  
178 -  
179 -  
180 # Copy test data in "data" directory 95 # Copy test data in "data" directory
181 -  
182 - os.system('cp -r %s %s' % (dirname+'/data', 'data'))  
183 -  
184 -  
185 - 96 + os.system('cp -r %s %s' % (dirname + '/data', 'data'))
186 # Set test data environment variable 97 # Set test data environment variable
187 -  
188 os.environ['TEST_DATA'] = 'data' 98 os.environ['TEST_DATA'] = 'data'
189 -  
190 -  
191 -  
192 # ... otherwise set the calibration database to the one shipped with the 99 # ... otherwise set the calibration database to the one shipped with the
193 -  
194 # package; we don't need to set the 'TEST_DATA', this is done by the 100 # package; we don't need to set the 'TEST_DATA', this is done by the
195 -  
196 # test environment 101 # test environment
197 -  
198 else: 102 else:
199 -  
200 os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) 103 os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR'])
201 -  
202 -  
203 -  
204 # Create a local "pfiles" directory and set PFILES environment variable 104 # Create a local "pfiles" directory and set PFILES environment variable
205 105
206 try: 106 try:
207 -  
208 os.mkdir('pfiles') 107 os.mkdir('pfiles')
209 -  
210 except: 108 except:
211 -  
212 pass 109 pass
213 110
214 os.environ['PFILES'] = 'pfiles' 111 os.environ['PFILES'] = 'pfiles'
215 112
216 -  
217 -  
218 # Copy the cscripts parameter files into the "pfiles" directory. For a 113 # Copy the cscripts parameter files into the "pfiles" directory. For a
219 -  
220 # non-installed test we copy the parameter files from the "cscripts" 114 # non-installed test we copy the parameter files from the "cscripts"
221 -  
222 # source directory into the "pfiles" directory, for an installed version 115 # source directory into the "pfiles" directory, for an installed version
223 -  
224 # we get all parameter files from the "syspfiles" directory. Also make 116 # we get all parameter files from the "syspfiles" directory. Also make
225 -  
226 # sure that all parameter files are writable. 117 # sure that all parameter files are writable.
227 118
228 if not installed: 119 if not installed:
229 -  
230 - os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR']))  
231 - 120 + os.system('cp -r %s/cscripts/*.par pfiles/' % (os.environ['TEST_SRCDIR']))
232 os.system('chmod u+w pfiles/*') 121 os.system('chmod u+w pfiles/*')
233 -  
234 else: 122 else:
235 -  
236 os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) 123 os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS']))
237 -  
238 os.system('chmod u+w pfiles/*') 124 os.system('chmod u+w pfiles/*')
239 125
240 -  
241 -  
242 # Define list of test suites 126 # Define list of test suites
243 -  
244 tests = [test_cscript.Test(), 127 tests = [test_cscript.Test(),
245 -  
246 test_csbkgmodel.Test(), 128 test_csbkgmodel.Test(),
247 -  
248 test_cscaldb.Test(), 129 test_cscaldb.Test(),
249 -  
250 test_csebins.Test(), 130 test_csebins.Test(),
251 -  
252 test_csinfo.Test(), 131 test_csinfo.Test(),
253 -  
254 test_cslightcrv.Test(), 132 test_cslightcrv.Test(),
255 -  
256 test_csmodelinfo.Test(), 133 test_csmodelinfo.Test(),
257 -  
258 test_csmodelmerge.Test(), 134 test_csmodelmerge.Test(),
259 -  
260 test_csmodelselect.Test(), 135 test_csmodelselect.Test(),
261 -  
262 test_csmodelsois.Test(), 136 test_csmodelsois.Test(),
263 -  
264 test_csobs2caldb.Test(), 137 test_csobs2caldb.Test(),
265 -  
266 test_csobsdef.Test(), 138 test_csobsdef.Test(),
267 -  
268 test_csobsinfo.Test(), 139 test_csobsinfo.Test(),
269 -  
270 test_csobsselect.Test(), 140 test_csobsselect.Test(),
271 -  
272 test_csphagen.Test(), 141 test_csphagen.Test(),
273 -  
274 test_csphasecrv.Test(), 142 test_csphasecrv.Test(),
275 -  
276 test_cspull.Test(), 143 test_cspull.Test(),
277 -  
278 test_csresmap.Test(), 144 test_csresmap.Test(),
279 -  
280 test_csresspec.Test(), 145 test_csresspec.Test(),
281 -  
282 test_csroot2caldb.Test(), 146 test_csroot2caldb.Test(),
283 -  
284 test_cssens.Test(), 147 test_cssens.Test(),
285 -  
286 test_csspec.Test(), 148 test_csspec.Test(),
287 -  
288 test_cssrcdetect.Test(), 149 test_cssrcdetect.Test(),
289 -  
290 test_cstsdist.Test(), 150 test_cstsdist.Test(),
291 -  
292 test_cstsmapmerge.Test(), 151 test_cstsmapmerge.Test(),
293 -  
294 test_cstsmapsplit.Test(), 152 test_cstsmapsplit.Test(),
295 -  
296 test_csviscube.Test(), 153 test_csviscube.Test(),
297 -  
298 test_csscs.Test(), 154 test_csscs.Test(),
299 test_csworkflow.Test(), 155 test_csworkflow.Test(),
300 -  
301 test_obsutils.Test(), 156 test_obsutils.Test(),
302 -  
303 test_mputils.Test()] 157 test_mputils.Test()]
304 158
305 -  
306 -  
307 # Append tests for Python 2.6+ (the IACT cscripts depend on the json 159 # Append tests for Python 2.6+ (the IACT cscripts depend on the json
308 -  
309 # module which is only available since Python 2.6+) 160 # module which is only available since Python 2.6+)
310 -  
311 ver = sys.version.split()[0] 161 ver = sys.version.split()[0]
312 -  
313 if ver >= '2.6.0': 162 if ver >= '2.6.0':
314 -  
315 -  
316 -  
317 # Check for VHEFITS environment variable 163 # Check for VHEFITS environment variable
318 -  
319 if 'VHEFITS' in os.environ: 164 if 'VHEFITS' in os.environ:
320 -  
321 -  
322 -  
323 # If the environment variable exists then unset it for the test 165 # If the environment variable exists then unset it for the test
324 -  
325 # cases. Since Python is executed in a subprocess this will not 166 # cases. Since Python is executed in a subprocess this will not
326 -  
327 # impact the environment variable in the parent shell. 167 # impact the environment variable in the parent shell.
328 -  
329 del os.environ['VHEFITS'] 168 del os.environ['VHEFITS']
330 169
331 -  
332 -  
333 # Append IACT script tests to list of test suites 170 # Append IACT script tests to list of test suites
334 -  
335 tests.extend([test_csfindobs.Test(), 171 tests.extend([test_csfindobs.Test(),
336 -  
337 test_csiactcopy.Test(), 172 test_csiactcopy.Test(),
338 -  
339 test_csiactdata.Test(), 173 test_csiactdata.Test(),
340 -  
341 test_csiactobs.Test()]) 174 test_csiactobs.Test()])
342 175
343 -  
344 -  
345 # Allocate test suite container 176 # Allocate test suite container
346 -  
347 suites = gammalib.GTestSuites('cscripts unit testing') 177 suites = gammalib.GTestSuites('cscripts unit testing')
348 178
349 -  
350 -  
351 # Set test suites and append them to suite container 179 # Set test suites and append them to suite container
352 -  
353 for suite in tests: 180 for suite in tests:
354 -  
355 suite.set() 181 suite.set()
356 -  
357 suites.append(suite) 182 suites.append(suite)
358 183
359 -  
360 -  
361 # Run test suite 184 # Run test suite
362 -  
363 success = suites.run() 185 success = suites.run()
364 186
365 -  
366 -  
367 # Save test results 187 # Save test results
368 -  
369 if not installed: 188 if not installed:
370 -  
371 suites.save('reports/cscripts.xml') 189 suites.save('reports/cscripts.xml')
372 -  
373 else: 190 else:
374 -  
375 suites.save('cscripts_reports.xml') 191 suites.save('cscripts_reports.xml')
376 192
377 -  
378 -  
379 # If debuging is requested then print test suites 193 # If debuging is requested then print test suites
380 -  
381 if debug: 194 if debug:
382 -  
383 print(suites) 195 print(suites)
384 196
385 -  
386 -  
387 # Remove temporary direction 197 # Remove temporary direction
388 -  
389 if installed: 198 if installed:
390 -  
391 os.system('rm -rf %s' % (path)) 199 os.system('rm -rf %s' % (path))
392 200
393 -  
394 -  
395 # Raise an exception in case of failure 201 # Raise an exception in case of failure
396 -  
397 if not success: 202 if not success:
398 -  
399 raise RuntimeError('At least one error occured during the test.') 203 raise RuntimeError('At least one error occured during the test.')
400 204
401 -  
402 -  
403 # Return 205 # Return
404 -  
405 return 206 return
406 207
407 208
408 -  
409 -  
410 -  
411 # ======================== # 209 # ======================== #
412 210
413 # Main routine entry point # 211 # Main routine entry point #
@@ -415,10 +213,6 @@ def test(installed=False, debug=False): @@ -415,10 +213,6 @@ def test(installed=False, debug=False):
415 # ======================== # 213 # ======================== #
416 214
417 if __name__ == '__main__': 215 if __name__ == '__main__':
418 -  
419 -  
420 -  
421 # Run tests 216 # Run tests
422 217
423 test() 218 test()
424 -