Commit 5ccf80776bcfdb7d7028fcbda4ce19cabe24074b

Authored by Jürgen Knödlseder
1 parent 9afc87bd

Increase code coverage (#1828)

test/test_csiactobs.py
... ... @@ -269,6 +269,7 @@ class Test(test):
269 269 self.test_value(obs.size(), obs_expected,
270 270 'Check for '+str(obs_expected)+' observations in XML file')
271 271  
  272 + # If there are observations in the XML file then check their content
272 273 if obs_expected > 0:
273 274  
274 275 # Get response
... ...
test/test_ctobssim.py
1 1 #! /usr/bin/env python
2 2 # ==========================================================================
3   -# This scripts performs unit tests for the ctobssim tool.
  3 +# This scripts performs unit tests for the ctobssim tool
4 4 #
5 5 # Copyright (C) 2014-2016 Juergen Knoedlseder
6 6 #
... ... @@ -165,10 +165,10 @@ class Test(test):
165 165 {'ra': 82.63, 'dec': 22.01}]
166 166 obs = obsutils.set_obs_list(pnts, caldb=self._caldb, irf=self._irf)
167 167  
168   - # Set-up ctobssim from observation container
  168 + # Set-up ctobssim tool from observation container
169 169 sim = ctools.ctobssim(obs)
170   - sim['outevents'] = 'ctobssim_py2.xml'
171 170 sim['inmodel'] = self._model
  171 + sim['outevents'] = 'ctobssim_py2.xml'
172 172 sim['logfile'] = 'ctobssim_py2.log'
173 173 sim['chatter'] = 3
174 174  
... ... @@ -178,7 +178,7 @@ class Test(test):
178 178 self.test_value(sim.max_rate(), 2*max_rate, 1.0e-3,
179 179 'Check setting of maximum event rate')
180 180  
181   - # Run tool
  181 + # Run ctobssim tool
182 182 sim.logFileOpen()
183 183 sim.run()
184 184  
... ... @@ -201,30 +201,31 @@ class Test(test):
201 201 self._test_list(obs[2].events(), 5955)
202 202 self._test_list(obs[3].events(), 6030)
203 203  
204   - # Set-up ctobssim with invalid event file
205   - sim = ctools.ctobssim()
206   - sim['inmodel'] = 'model_file_that_does_not_exist.xml'
207   - sim['caldb'] = self._caldb
208   - sim['irf'] = self._irf
209   - sim['ra'] = 83.63
210   - sim['dec'] = 22.01
211   - sim['rad'] = 10.0
212   - sim['tmin'] = 0.0
213   - sim['tmax'] = 1800.0
214   - sim['emin'] = 0.1
215   - sim['emax'] = 100.0
216   - sim['outevents'] = 'ctobssim_py3.fits'
217   - sim['logfile'] = 'ctobssim_py3.log'
218   - sim['chatter'] = 4
219   -
220   - # Run ctbin tool
221   - self.test_try('Run ctobssim with invalid model file')
222   - try:
223   - sim.logFileOpen()
224   - sim.run()
225   - self.test_try_failure()
226   - except:
227   - self.test_try_success()
  204 + # Copy ctobssim tool
  205 + cpy_sim = sim.copy()
  206 +
  207 + # Retrieve observation and check content of copy
  208 + self._test_observation(cpy_sim, nobs=4, pnts=pnts)
  209 + self._test_list(cpy_sim.obs()[0].events(), 6003)
  210 + self._test_list(cpy_sim.obs()[1].events(), 6084)
  211 + self._test_list(cpy_sim.obs()[2].events(), 5955)
  212 + self._test_list(cpy_sim.obs()[3].events(), 6030)
  213 +
  214 + # Execute copy of ctobssim tool again, now with a higher chatter
  215 + # level than before
  216 + cpy_sim['outevents'] = 'ctobssim_py3.xml'
  217 + cpy_sim['logfile'] = 'ctobssim_py3.log'
  218 + cpy_sim['chatter'] = 4
  219 + cpy_sim.logFileOpen() # Needed to get a new log file
  220 + cpy_sim.execute()
  221 +
  222 + # Check result file
  223 + obs = gammalib.GObservations('ctobssim_py3.xml')
  224 + self.test_value(obs.size(), 4, 'Check for number of observations')
  225 + self._test_list(obs[0].events(), 6003)
  226 + self._test_list(obs[1].events(), 6084)
  227 + self._test_list(obs[2].events(), 5955)
  228 + self._test_list(obs[3].events(), 6030)
228 229  
229 230 # Return
230 231 return
... ...