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