Commit 55989652f0a2e2bdf63bc2179a13dc7a79d88a3c
1 parent
e0ba2a94
Enhance branch coverage (#1828)
Showing
2 changed files
with
49 additions
and
4 deletions
test/test_cscript.py
| ... | ... | @@ -56,7 +56,7 @@ class cscript_test(ctools.cscript): |
| 56 | 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, events, cube) | |
| 59 | + self._setup_observations(obs, False, events, cube) | |
| 60 | 60 | return |
| 61 | 61 | |
| 62 | 62 | # Check setup_models() method |
| ... | ... | @@ -76,6 +76,12 @@ class cscript_test(ctools.cscript): |
| 76 | 76 | self._require_inobs('check_require_inobs') |
| 77 | 77 | return |
| 78 | 78 | |
| 79 | + # Check require_inobs_nocube() method | |
| 80 | + def check_require_inobs_nocube(self, filename): | |
| 81 | + self.pars()['inobs'].value(filename) | |
| 82 | + self._require_inobs_nocube('check_require_inobs_nocube') | |
| 83 | + return | |
| 84 | + | |
| 79 | 85 | # Check get_roi() method |
| 80 | 86 | def check_get_roi(self): |
| 81 | 87 | return self._get_roi() |
| ... | ... | @@ -125,6 +131,14 @@ class ctobservation_test(ctools.csobservation): |
| 125 | 131 | # Return |
| 126 | 132 | return |
| 127 | 133 | |
| 134 | + # Check first_unbinned_observation() method | |
| 135 | + def check_first_unbinned_observation(self): | |
| 136 | + return self._first_unbinned_observation() | |
| 137 | + | |
| 138 | + # Check next_unbinned_observation() method | |
| 139 | + def check_next_unbinned_observation(self): | |
| 140 | + return self._next_unbinned_observation() | |
| 141 | + | |
| 128 | 142 | |
| 129 | 143 | # ======================= # |
| 130 | 144 | # ctlikelihood_test class # |
| ... | ... | @@ -245,6 +259,14 @@ class Test(test): |
| 245 | 259 | except ValueError: |
| 246 | 260 | self.test_try_success() |
| 247 | 261 | |
| 262 | + # Test setup_observations() for acceptable event list | |
| 263 | + self.test_try('Check setup_observations() for acceptable event list') | |
| 264 | + try: | |
| 265 | + empty.check_setup_observations(self._events, events=True) | |
| 266 | + self.test_try_success() | |
| 267 | + except ValueError: | |
| 268 | + self.test_try_failure('Exception thrown') | |
| 269 | + | |
| 248 | 270 | # Test setup_observations() for unacceptable event list |
| 249 | 271 | self.test_try('Check setup_observations() for unacceptable event list') |
| 250 | 272 | try: |
| ... | ... | @@ -253,6 +275,14 @@ class Test(test): |
| 253 | 275 | except ValueError: |
| 254 | 276 | self.test_try_success() |
| 255 | 277 | |
| 278 | + # Test setup_observations() for acceptable counts cube | |
| 279 | + self.test_try('Check setup_observations() for acceptable counts cube') | |
| 280 | + try: | |
| 281 | + empty.check_setup_observations(self._cntcube, cube=True) | |
| 282 | + self.test_try_success() | |
| 283 | + except ValueError: | |
| 284 | + self.test_try_failure('Exception thrown') | |
| 285 | + | |
| 256 | 286 | # Test setup_observations() for unacceptable counts cube |
| 257 | 287 | self.test_try('Check setup_observations() for unacceptable counts cube') |
| 258 | 288 | try: |
| ... | ... | @@ -303,6 +333,14 @@ class Test(test): |
| 303 | 333 | except ValueError: |
| 304 | 334 | self.test_try_success() |
| 305 | 335 | |
| 336 | + # Test require_inobs_nocube() method for invalid file name | |
| 337 | + self.test_try('Check require_inobs_nocube() method for counts cube') | |
| 338 | + try: | |
| 339 | + empty.check_require_inobs_nocube(self._cntcube) | |
| 340 | + self.test_try_failure('Exception not thrown') | |
| 341 | + except ValueError: | |
| 342 | + self.test_try_success() | |
| 343 | + | |
| 306 | 344 | # Test get_roi() method |
| 307 | 345 | roi = empty.check_get_roi() |
| 308 | 346 | self.test_assert(not roi.is_valid(), 'Check get_roi() method') |
| ... | ... | @@ -351,11 +389,11 @@ class Test(test): |
| 351 | 389 | empty = ctobservation_test() |
| 352 | 390 | |
| 353 | 391 | # Test first_unbinned_observation() method |
| 354 | - self.test_assert(empty._first_unbinned_observation() is None, | |
| 392 | + self.test_assert(empty.check_first_unbinned_observation() is None, | |
| 355 | 393 | 'Check first_unbinned_observation() method') |
| 356 | 394 | |
| 357 | 395 | # Test next_unbinned_observation() method |
| 358 | - self.test_assert(empty._next_unbinned_observation() is None, | |
| 396 | + self.test_assert(empty.check_next_unbinned_observation() is None, | |
| 359 | 397 | 'Check next_unbinned_observation() method') |
| 360 | 398 | |
| 361 | 399 | # Return | ... | ... |
test/test_ctbin.py
| ... | ... | @@ -101,6 +101,13 @@ class Test(test): |
| 101 | 101 | self.test_assert(self._execute(cmd) != 0, |
| 102 | 102 | 'Check invalid input file when executed from command line') |
| 103 | 103 | |
| 104 | + # Setup ctbin --help option | |
| 105 | + cmd = ctbin+' --help' | |
| 106 | + | |
| 107 | + # Check if execution was successful | |
| 108 | + self.test_assert(self._execute(cmd) == 0, | |
| 109 | + 'Check successful execution from command line with --help option') | |
| 110 | + | |
| 104 | 111 | # Return |
| 105 | 112 | return |
| 106 | 113 | |
| ... | ... | @@ -231,7 +238,7 @@ class Test(test): |
| 231 | 238 | |
| 232 | 239 | # And finally go for a fully Pythonic version with all parameters |
| 233 | 240 | # being specified in a dictionary |
| 234 | - pars = {'inobs': self._events, 'ebinalg': 'LOG', 'emin': 0.1, | |
| 241 | + pars = {'inobs': self._events, 'ebinalg': 'LIN', 'emin': 0.1, | |
| 235 | 242 | 'emax': 100.0, 'enumbins': 10, 'nxpix': 40, 'nypix': 40, |
| 236 | 243 | 'binsz': 0.1, 'coordsys': 'CEL', 'proj': 'CAR', |
| 237 | 244 | 'xref': 83.63, 'yref': 22.01, 'outcube': 'ctbin_py4.fits', | ... | ... |