Commit e0ba2a94009e75b998e12979d8faf924d427edd7

Authored by Jürgen Knödlseder
1 parent 35b1bdd3

Enhance code quality (#1828)

test/test_cscript.py
... ... @@ -49,56 +49,56 @@ class cscript_test(ctools.cscript):
49 49 return
50 50  
51 51 # Check is_valid_filename() method
52   - def _check_is_valid_filename(self, filename):
  52 + def check_is_valid_filename(self, filename):
53 53 return self._is_valid_filename(gammalib.GFilename(filename))
54 54  
55 55 # Check setup_observations() method
56   - def _check_setup_observations(self, filename, list=True, cube=True):
  56 + def check_setup_observations(self, filename, events=True, cube=True):
57 57 self.pars()['inobs'].value(filename)
58 58 obs = gammalib.GObservations()
59   - self._setup_observations(obs, True, list, cube)
  59 + self._setup_observations(obs, True, events, cube)
60 60 return
61 61  
62 62 # Check setup_models() method
63   - def _check_setup_models(self):
  63 + def check_setup_models(self):
64 64 obs = gammalib.GObservations()
65 65 self._setup_models(obs)
66 66 return
67 67  
68 68 # Check create_ebounds() method
69   - def _check_create_ebounds(self, filename):
  69 + def check_create_ebounds(self, filename):
70 70 self.pars()['ebinfile'].value(filename)
71 71 return self._create_ebounds()
72 72  
73 73 # Check require_inobs() method
74   - def _check_require_inobs(self, filename):
  74 + def check_require_inobs(self, filename):
75 75 self.pars()['inobs'].value(filename)
76   - self._require_inobs('_check_require_inobs')
  76 + self._require_inobs('check_require_inobs')
77 77 return
78 78  
79 79 # Check get_roi() method
80   - def _check_get_roi(self):
  80 + def check_get_roi(self):
81 81 return self._get_roi()
82 82  
83 83 # Check restore_edisp() method
84   - def _check_restore_edisp(self):
  84 + def check_restore_edisp(self):
85 85 obs = gammalib.GObservations()
86 86 edisp = [True, True]
87 87 self._restore_edisp(obs, edisp)
88 88 return
89 89  
90 90 # Check set_obs_bounds() method
91   - def _check_set_obs_bounds(self):
92   - obs = gammalib.GObservations()
93   - list = gammalib.GCTAEventList()
94   - cta = gammalib.GCTAObservation()
95   - cta.events(list)
  91 + def check_set_obs_bounds(self):
  92 + obs = gammalib.GObservations()
  93 + events = gammalib.GCTAEventList()
  94 + cta = gammalib.GCTAObservation()
  95 + cta.events(events)
96 96 obs.append(cta)
97 97 self._set_obs_bounds(obs)
98 98 return obs.copy()
99 99  
100 100 # Check get_mean_pointing() method
101   - def _check_get_mean_pointing(self):
  101 + def check_get_mean_pointing(self):
102 102 obs = gammalib.GObservations()
103 103 return self._get_mean_pointing(obs)
104 104  
... ... @@ -149,7 +149,7 @@ class ctlikelihood_test(ctools.cslikelihood):
149 149 return
150 150  
151 151 # Check evaluate() method
152   - def _check_evaluate(self, value):
  152 + def check_evaluate(self, value):
153 153 par = gammalib.GModelPar()
154 154 par.value(2.0)
155 155 par.range(1.0, 3.0)
... ... @@ -230,17 +230,17 @@ class Test(test):
230 230 empty = cscript_test()
231 231  
232 232 # Test is_valid_filename() method
233   - self.test_assert(empty._check_is_valid_filename(self._model),
  233 + self.test_assert(empty.check_is_valid_filename(self._model),
234 234 'Check model definiton XML file')
235   - self.test_assert(not empty._check_is_valid_filename(''),
  235 + self.test_assert(not empty.check_is_valid_filename(''),
236 236 'Check empty filename')
237   - self.test_assert(not empty._check_is_valid_filename('NONE'),
  237 + self.test_assert(not empty.check_is_valid_filename('NONE'),
238 238 'Check "NONE" filename')
239 239  
240 240 # Test setup_observations() for invalid file name
241 241 self.test_try('Check setup_observations() for "NONE"')
242 242 try:
243   - empty._check_setup_observations('NONE')
  243 + empty.check_setup_observations('NONE')
244 244 self.test_try_failure('Exception not thrown')
245 245 except ValueError:
246 246 self.test_try_success()
... ... @@ -248,7 +248,7 @@ class Test(test):
248 248 # Test setup_observations() for unacceptable event list
249 249 self.test_try('Check setup_observations() for unacceptable event list')
250 250 try:
251   - empty._check_setup_observations(self._events, list=False)
  251 + empty.check_setup_observations(self._events, events=False)
252 252 self.test_try_failure('Exception not thrown')
253 253 except ValueError:
254 254 self.test_try_success()
... ... @@ -256,7 +256,7 @@ class Test(test):
256 256 # Test setup_observations() for unacceptable counts cube
257 257 self.test_try('Check setup_observations() for unacceptable counts cube')
258 258 try:
259   - empty._check_setup_observations(self._cntcube, cube=False)
  259 + empty.check_setup_observations(self._cntcube, cube=False)
260 260 self.test_try_failure('Exception not thrown')
261 261 except ValueError:
262 262 self.test_try_success()
... ... @@ -264,19 +264,19 @@ class Test(test):
264 264 # Test setup_models() for invalid model definition file name
265 265 self.test_try('Check setup_models() for invalid model definition file name')
266 266 try:
267   - empty._check_setup_models()
  267 + empty.check_setup_models()
268 268 self.test_try_failure('Exception not thrown')
269 269 except ValueError:
270 270 self.test_try_success()
271 271  
272 272 # Test create_ebounds() method for "EBOUNDS" extension
273   - ebounds = empty._check_create_ebounds('test_ebinfile_ebounds.fits')
  273 + ebounds = empty.check_create_ebounds('test_ebinfile_ebounds.fits')
274 274 self.test_value(ebounds.size(), 1, 'Check number of energy boundaries')
275 275 self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy')
276 276 self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy')
277 277  
278 278 # Test create_ebounds() method for "ENERGYBINS" extension
279   - ebounds = empty._check_create_ebounds('test_ebinfile_energybins.fits')
  279 + ebounds = empty.check_create_ebounds('test_ebinfile_energybins.fits')
280 280 self.test_value(ebounds.size(), 1, 'Check number of energy boundaries')
281 281 self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy')
282 282 self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy')
... ... @@ -284,27 +284,33 @@ class Test(test):
284 284 # Test create_ebounds() method for invalid extension
285 285 self.test_try('Check create_ebounds() method for invalid extension')
286 286 try:
287   - empty._check_create_ebounds('test_ebinfile_energies.fits')
  287 + empty.check_create_ebounds('test_ebinfile_energies.fits')
288 288 self.test_try_failure('Exception not thrown')
289 289 except ValueError:
290 290 self.test_try_success()
291 291  
  292 + # Test create_ebounds() method for "ENERGIES" extension
  293 + ebounds = empty.check_create_ebounds('test_ebinfile_energies.fits[ENERGIES]')
  294 + self.test_value(ebounds.size(), 1, 'Check number of energy boundaries')
  295 + self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy')
  296 + self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy')
  297 +
292 298 # Test require_inobs() method for invalid file name
293 299 self.test_try('Check require_inobs() method for invalid file name')
294 300 try:
295   - empty._check_require_inobs('NONE')
  301 + empty.check_require_inobs('NONE')
296 302 self.test_try_failure('Exception not thrown')
297 303 except ValueError:
298 304 self.test_try_success()
299 305  
300 306 # Test get_roi() method
301   - roi = empty._check_get_roi()
  307 + roi = empty.check_get_roi()
302 308 self.test_assert(not roi.is_valid(), 'Check get_roi() method')
303 309  
304 310 # Test restore_edisp() method for invalid vector size
305 311 #self.test_try('Check restore_edisp() method for invalid vector size')
306 312 #try:
307   - # empty._check_restore_edisp()
  313 + # empty.check_restore_edisp()
308 314 # self.test_try_failure('Exception not thrown')
309 315 #except ValueError:
310 316 # self.test_try_success()
... ... @@ -313,7 +319,7 @@ class Test(test):
313 319 # integer vector conversion.
314 320  
315 321 # Test set_obs_bounds() method
316   - obs = empty._check_set_obs_bounds()
  322 + obs = empty.check_set_obs_bounds()
317 323 self.test_value(obs.size(), 1, 'Check number of observations')
318 324 self.test_value(obs[0].events().ebounds().size(), 1,
319 325 'Check number of energy boundaries')
... ... @@ -328,7 +334,7 @@ class Test(test):
328 334 self.test_try('Check get_mean_pointing() method for empty observation '
329 335 'container')
330 336 try:
331   - empty._check_get_mean_pointing()
  337 + empty.check_get_mean_pointing()
332 338 self.test_try_failure('Exception not thrown')
333 339 except ValueError:
334 340 self.test_try_success()
... ... @@ -366,7 +372,7 @@ class Test(test):
366 372 # Test evaluate() method for minimum value violation
367 373 self.test_try('Check evaluate() for minimum value violation')
368 374 try:
369   - empty._check_evaluate(0.0)
  375 + empty.check_evaluate(0.0)
370 376 self.test_try_failure('Exception not thrown')
371 377 except ValueError:
372 378 self.test_try_success()
... ... @@ -374,7 +380,7 @@ class Test(test):
374 380 # Test evaluate() method for maximum value violation
375 381 self.test_try('Check evaluate() for maximum value violation')
376 382 try:
377   - empty._check_evaluate(4.0)
  383 + empty.check_evaluate(4.0)
378 384 self.test_try_failure('Exception not thrown')
379 385 except ValueError:
380 386 self.test_try_success()
... ...
test/test_ctskymap.py
... ... @@ -152,13 +152,15 @@ class Test(test):
152 152  
153 153 # Execute copy of ctskymap tool again, now with a higher chatter
154 154 # level than before
155   - cpy_skymap['usepnt'] = True
156   - cpy_skymap['emin'] = 0.2
157   - cpy_skymap['emax'] = 150.0
158   - cpy_skymap['outmap'] = 'ctskymap_py2.fits'
159   - cpy_skymap['logfile'] = 'ctskymap_py2.log'
160   - cpy_skymap['publish'] = True
161   - cpy_skymap['chatter'] = 3
  155 + cpy_skymap['usepnt'] = True
  156 + cpy_skymap['emin'] = 0.2
  157 + cpy_skymap['emax'] = 150.0
  158 + cpy_skymap['coordsys'] = 'GAL'
  159 + cpy_skymap['proj'] = 'CAR'
  160 + cpy_skymap['outmap'] = 'ctskymap_py2.fits'
  161 + cpy_skymap['logfile'] = 'ctskymap_py2.log'
  162 + cpy_skymap['publish'] = True
  163 + cpy_skymap['chatter'] = 3
162 164 cpy_skymap.logFileOpen() # Needed to get a new log file
163 165 cpy_skymap.execute()
164 166  
... ...