Commit c58647da9f9d4397ff1f97e09487a3ec78ff44a6
1 parent
4896609d
Increase ctool base class coverage
Showing
1 changed file
with
155 additions
and
30 deletions
test/test_cscript.py
| ... | ... | @@ -48,10 +48,6 @@ class cscript_test(ctools.cscript): |
| 48 | 48 | # Return |
| 49 | 49 | return |
| 50 | 50 | |
| 51 | - # Check is_valid_filename() method | |
| 52 | - def check_is_valid_filename(self, filename): | |
| 53 | - return self._is_valid_filename(gammalib.GFilename(filename)) | |
| 54 | - | |
| 55 | 51 | # Check setup_observations() method |
| 56 | 52 | def check_setup_observations(self, filename, events=True, cube=True): |
| 57 | 53 | self.pars()['inobs'].value(filename) |
| ... | ... | @@ -126,6 +122,23 @@ class cscript_test(ctools.cscript): |
| 126 | 122 | def check_get_current_rss(self): |
| 127 | 123 | return self._get_current_rss() |
| 128 | 124 | |
| 125 | + # Check is_valid_filename() method | |
| 126 | + def check_is_valid_filename(self, filename): | |
| 127 | + return self._is_valid_filename(gammalib.GFilename(filename)) | |
| 128 | + | |
| 129 | + # Check save_event_list() method | |
| 130 | + def check_save_event_list(self, infile, evtname, gtiname, outfile): | |
| 131 | + obs = gammalib.GCTAObservation() | |
| 132 | + events = gammalib.GCTAEventList() | |
| 133 | + obs.events(events) | |
| 134 | + obs.save(infile, True) | |
| 135 | + self._save_event_list(obs, infile, evtname, gtiname, outfile) | |
| 136 | + return | |
| 137 | + | |
| 138 | + # Check warn_xml_suffix() method | |
| 139 | + def check_warn_xml_suffix(self, filename): | |
| 140 | + return self._warn_xml_suffix(gammalib.GFilename(filename)) | |
| 141 | + | |
| 129 | 142 | |
| 130 | 143 | # ======================== # |
| 131 | 144 | # ctobservation_test class # |
| ... | ... | @@ -276,13 +289,14 @@ class Test(test): |
| 276 | 289 | # Allocate empty |
| 277 | 290 | empty = cscript_test() |
| 278 | 291 | |
| 279 | - # Test is_valid_filename() method | |
| 280 | - self.test_assert(empty.check_is_valid_filename(self._model), | |
| 281 | - 'Check model definiton XML file') | |
| 282 | - self.test_assert(not empty.check_is_valid_filename(''), | |
| 283 | - 'Check empty filename') | |
| 284 | - self.test_assert(not empty.check_is_valid_filename('NONE'), | |
| 285 | - 'Check "NONE" filename') | |
| 292 | + # Test read_ahead() method | |
| 293 | + # TODO: implement | |
| 294 | + | |
| 295 | + # Test time_reference() method | |
| 296 | + # TODO: implement | |
| 297 | + | |
| 298 | + # Test get_observations() method | |
| 299 | + # TODO: implement | |
| 286 | 300 | |
| 287 | 301 | # Test setup_observations() for invalid file name |
| 288 | 302 | self.test_try('Check setup_observations() for "NONE"') |
| ... | ... | @@ -370,6 +384,15 @@ class Test(test): |
| 370 | 384 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') |
| 371 | 385 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') |
| 372 | 386 | |
| 387 | + # Test create_map() method | |
| 388 | + # TODO: implement | |
| 389 | + | |
| 390 | + # Test create_cube() method | |
| 391 | + # TODO: implement | |
| 392 | + | |
| 393 | + # Test create_cta_obs() method | |
| 394 | + # TODO: implement | |
| 395 | + | |
| 373 | 396 | # Test require_inobs() method for invalid file name |
| 374 | 397 | self.test_try('Check require_inobs() method for invalid file name') |
| 375 | 398 | try: |
| ... | ... | @@ -398,6 +421,30 @@ class Test(test): |
| 398 | 421 | roi = empty.check_get_roi() |
| 399 | 422 | self.test_assert(not roi.is_valid(), 'Check get_roi() method') |
| 400 | 423 | |
| 424 | + # Test get_ebounds() method | |
| 425 | + # TODO: implement | |
| 426 | + | |
| 427 | + # Test get_gti() method | |
| 428 | + # TODO: implement | |
| 429 | + | |
| 430 | + # Test get_pointing() method | |
| 431 | + # TODO: implement | |
| 432 | + | |
| 433 | + # Test get_skydir() method | |
| 434 | + # TODO: implement | |
| 435 | + | |
| 436 | + # Test set_outfile_name() method | |
| 437 | + # TODO: implement | |
| 438 | + | |
| 439 | + # Test is_stacked() method | |
| 440 | + # TODO: implement | |
| 441 | + | |
| 442 | + # Test set_response() method | |
| 443 | + # TODO: implement | |
| 444 | + | |
| 445 | + # Test set_edisp() method | |
| 446 | + # TODO: implement | |
| 447 | + | |
| 401 | 448 | # Test restore_edisp() method for invalid vector size |
| 402 | 449 | self.test_try('Check restore_edisp() method for invalid vector size') |
| 403 | 450 | try: |
| ... | ... | @@ -406,6 +453,25 @@ class Test(test): |
| 406 | 453 | except ValueError: |
| 407 | 454 | self.test_try_success() |
| 408 | 455 | |
| 456 | + # Test set_obs_response() method with 'NONE' files. If energy dispersion | |
| 457 | + # is requested then an exception will be thrown. | |
| 458 | + empty.check_set_obs_response('NONE', 'NONE', 'NONE', 'NONE', 'no') | |
| 459 | + empty.check_set_obs_response('NONE', 'NONE', 'NONE', 'NONE', 'yes') | |
| 460 | + self.test_try('Check set_obs_response() method for file names') | |
| 461 | + try: | |
| 462 | + empty.check_set_obs_response(self._datadir+'/crab_expcube.fits', | |
| 463 | + self._datadir+'/crab_psfcube.fits', | |
| 464 | + self._datadir+'/crab_bkgcube.fits', | |
| 465 | + 'NONE', 'yes') | |
| 466 | + self.test_try_failure('Exception not thrown') | |
| 467 | + except ValueError: | |
| 468 | + self.test_try_success() | |
| 469 | + empty.check_set_obs_response(self._datadir+'/crab_expcube.fits', | |
| 470 | + self._datadir+'/crab_psfcube.fits', | |
| 471 | + self._datadir+'/crab_bkgcube.fits', | |
| 472 | + self._datadir+'/crab_edispcube.fits', | |
| 473 | + 'yes') | |
| 474 | + | |
| 409 | 475 | # Test set_obs_bounds() method |
| 410 | 476 | obs = empty.check_set_obs_bounds() |
| 411 | 477 | self.test_value(obs.size(), 1, 'Check number of observations') |
| ... | ... | @@ -427,28 +493,87 @@ class Test(test): |
| 427 | 493 | except ValueError: |
| 428 | 494 | self.test_try_success() |
| 429 | 495 | |
| 430 | - # Test set_obs_response() method with 'NONE' files. If energy dispersion | |
| 431 | - # is requested then an exception will be thrown. | |
| 432 | - empty.check_set_obs_response('NONE', 'NONE', 'NONE', 'NONE', 'no') | |
| 433 | - empty.check_set_obs_response('NONE', 'NONE', 'NONE', 'NONE', 'yes') | |
| 434 | - self.test_try('Check set_obs_response() method for file names') | |
| 435 | - try: | |
| 436 | - empty.check_set_obs_response(self._datadir+'/crab_expcube.fits', | |
| 437 | - self._datadir+'/crab_psfcube.fits', | |
| 438 | - self._datadir+'/crab_bkgcube.fits', | |
| 439 | - 'NONE', 'yes') | |
| 440 | - self.test_try_failure('Exception not thrown') | |
| 441 | - except ValueError: | |
| 442 | - self.test_try_success() | |
| 443 | - empty.check_set_obs_response(self._datadir+'/crab_expcube.fits', | |
| 444 | - self._datadir+'/crab_psfcube.fits', | |
| 445 | - self._datadir+'/crab_bkgcube.fits', | |
| 446 | - self._datadir+'/crab_edispcube.fits', | |
| 447 | - 'yes') | |
| 448 | - | |
| 449 | 496 | # Test get_current_rss() method |
| 450 | 497 | empty.check_get_current_rss() |
| 451 | 498 | |
| 499 | + # Test get_obs_header() method | |
| 500 | + # TODO: implement | |
| 501 | + | |
| 502 | + # Test insert_energy_boundaries() method | |
| 503 | + # TODO: implement | |
| 504 | + | |
| 505 | + # Test cube_layer_usage() method | |
| 506 | + # TODO: implement | |
| 507 | + | |
| 508 | + # Test is_valid_filename() method | |
| 509 | + self.test_assert(empty.check_is_valid_filename(self._model), | |
| 510 | + 'Check model definiton XML file') | |
| 511 | + self.test_assert(not empty.check_is_valid_filename(''), | |
| 512 | + 'Check empty filename') | |
| 513 | + self.test_assert(not empty.check_is_valid_filename('NONE'), | |
| 514 | + 'Check "NONE" filename') | |
| 515 | + | |
| 516 | + # Test get_gtiname() method | |
| 517 | + # TODO: implement | |
| 518 | + | |
| 519 | + # Check save_event_list() method | |
| 520 | + empty.check_save_event_list('test_event_list_input1.fits', 'EVENTS', | |
| 521 | + 'GTI', 'test_event_list_output1.fits') | |
| 522 | + self._test_cscript_save_event_list('test_event_list_output1.fits', | |
| 523 | + ['Primary','EVENTS','GTI']) | |
| 524 | + empty.check_save_event_list('test_event_list_input2.fits', 'EVENTS', | |
| 525 | + 'GTI', 'test_event_list_output2.fits[EVT]') | |
| 526 | + self._test_cscript_save_event_list('test_event_list_output2.fits', | |
| 527 | + ['Primary','EVT','GTI']) | |
| 528 | + empty.check_save_event_list('test_event_list_input3.fits', 'EVENTS', | |
| 529 | + 'GTI', 'test_event_list_output3.fits[EVT;TIME]') | |
| 530 | + self._test_cscript_save_event_list('test_event_list_output3.fits', | |
| 531 | + ['Primary','EVT','TIME']) | |
| 532 | + empty.check_save_event_list('test_event_list_input4.fits', 'EVENTS', | |
| 533 | + 'GTI', 'test_event_list_output4.fits[EVT;]') | |
| 534 | + self._test_cscript_save_event_list('test_event_list_output4.fits', | |
| 535 | + ['Primary','EVT','GTI']) | |
| 536 | + empty.check_save_event_list('test_event_list_input5.fits', 'EVENTS', | |
| 537 | + 'GTI', 'test_event_list_output5.fits[;TIME]') | |
| 538 | + self._test_cscript_save_event_list('test_event_list_output5.fits', | |
| 539 | + ['Primary','EVENTS','TIME']) | |
| 540 | + empty.check_save_event_list('test_event_list_input6.fits', 'XEVENTS', | |
| 541 | + 'XGTI', 'test_event_list_output6.fits[EVT;TIME]') | |
| 542 | + self._test_cscript_save_event_list('test_event_list_output6.fits', | |
| 543 | + ['Primary','EVT','TIME','EVENTS','GTI']) | |
| 544 | + | |
| 545 | + # Test warn_too_few_energies() method | |
| 546 | + # TODO: implement | |
| 547 | + | |
| 548 | + # Test warn_xml_suffix() method | |
| 549 | + self.test_value(len(empty.check_warn_xml_suffix('test.xml')), 0, | |
| 550 | + 'Check xml suffix warning for "test.xml" file') | |
| 551 | + self.test_value(len(empty.check_warn_xml_suffix('test.fits')), 235, | |
| 552 | + 'Check xml suffix warning for "test.fits" file') | |
| 553 | + | |
| 554 | + # Test provide_help() method | |
| 555 | + # TODO: implement | |
| 556 | + | |
| 557 | + # Return | |
| 558 | + return | |
| 559 | + | |
| 560 | + # Test check_save_event_list() method result | |
| 561 | + def _test_cscript_save_event_list(self, filename, hdunames): | |
| 562 | + """ | |
| 563 | + Test check_save_event_list() method result | |
| 564 | + """ | |
| 565 | + # Open FITS file | |
| 566 | + fits = gammalib.GFits(filename) | |
| 567 | + | |
| 568 | + # Check number of HDUs | |
| 569 | + self.test_value(fits.size(), len(hdunames), 'save_event_list(): ' | |
| 570 | + 'Check number of FITS HDUs in file %s' % filename) | |
| 571 | + | |
| 572 | + # Check HDU extension names | |
| 573 | + for i, hdu in enumerate(fits): | |
| 574 | + self.test_value(hdu.extname(), hdunames[i], 'save_event_list(): ' | |
| 575 | + 'Check FITS HDU extension name in file %s' % filename) | |
| 576 | + | |
| 452 | 577 | # Return |
| 453 | 578 | return |
| 454 | 579 | ... | ... |