From c41c774afda57845fb9b4032ba6daad5fb5295f9 Mon Sep 17 00:00:00 2001 From: jperrot Date: Mon, 28 Aug 2017 11:29:05 +0200 Subject: [PATCH] test ctselect add functionnal tests and invalide phase tests --- test/test_ctselect.py | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 188 insertions(+), 157 deletions(-) diff --git a/test/test_ctselect.py b/test/test_ctselect.py index 6a32deb..fa3d43a 100755 --- a/test/test_ctselect.py +++ b/test/test_ctselect.py @@ -56,11 +56,9 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test ctselect on command line') - self.append(self._test_empty_ctselect_tool, 'CTSELECT - Test empty ctselect tool') - self.append(self._test_saving_empty_does_nothing, 'CTSELECT - Test saving empty does nothing') - self.append(self._test_with_parameters,'CTSELECT - Test with parameters') + self.append(self._test_init, 'CTSELECT - Test constructor and init') + self.append(self._test_save_empty_does_nothing, 'CTSELECT - Test save empty does nothing') self.append(self._test_time_selection,'CTSELECT - Test time_selection') - self.append(self._test_for_ctselect_copy,'CTSELECT - Test ctselect copy') self.append(self._test_set_emin_emax, 'CTSELECT - Test set emin emax') self.append(self._test_clear,'CTSELECT - Test Clear') self.append(self._test_copy,'CTSELECT - Test Copy') @@ -79,7 +77,14 @@ class Test(test): self.append(self._test_phase_selection_2inter, 'CTSELECT - Test phase_selection 2 interval') self.append(self._test_phase_selection_first_inter, 'CTSELECT - Test phase_selection first interval') self.append(self._test_phase_selection_second_inter, 'CTSELECT - Test phase_selection second interval') - self.append(self._test_invalid_phase_value_string, 'CTSELECT - Test invalid phase value or string') + self.append(self._test_phase_invalid_min_negative,'CTSELECT - Test phase min negative value') + self.append(self._test_phase_invalid_max_negative,'CTSELECT - Test phase max negative value') + self.append(self._test_phase_invalid_minsupmax,'CTSELECT - Test phase min sup max') + self.append(self._test_phase_invalid_missmin,'CTSELECT - Test phase missing min value') + self.append(self._test_phase_invalid_missmax,'CTSELECT - Test phase missing max value') + self.append(self._test_phase_invalid_syntax,'CTSELECT - Test phase invalid syntax') + self.append(self._FuncTest_copy_none,'CTSELECT - Functionnal Test ctselect copy and none param') + self.append(self._Functest_with_parameters,'CTSELECT - Test with parameters') # Return return @@ -299,8 +304,8 @@ class Test(test): # Return return - # Unit Test empty ctselect tool - def _test_empty_ctselect_tool(self): + # Unit Test constructor and init ------------------------------------------------------------------ + def _test_init(self): """ Unit Test empty ctselect tool @@ -315,16 +320,16 @@ class Test(test): # Return return - # Unit Test saving does nothing - def _test_saving_empty_does_nothing(self): + # Unit Test save empty does nothing ----------------------------------------------------------------- + def _test_save_empty_does_nothing(self): """ Unit Test saving empty does nothing """ - select = self._setup(outobs='ctselect_py0.fits',logfile='ctselect_py0.log') + select = self._setup(outobs='ctselect_py_SaveEmpty.fits',logfile='ctselect_py_SaveEmpty.log') select.save() - self.test_assert(not os.path.isfile('ctselect_py0.fits'), + self.test_assert(not os.path.isfile('ctselect_py_SaveEmpty.fits'), 'Check that no event list has been created') self._teardown(select) @@ -332,29 +337,7 @@ class Test(test): # Return return - # Unit Test with parameters - def _test_with_parameters(self): - """ - Unit Test with parameters - - """ - select = self._setup(inobs=self._events,tmin=500.0,tmax=1000.0,emin=0.2,emax=80,outobs='ctselect_py21.fits',logfile='ctselect_py21.log') - - # Run ctselect tool - select.logFileOpen() # Make sure we get a log file - select.run() - select.save() - - # Check result file - self._check_result_file('ctselect_py21.fits', 'with parameters') - - - self._teardown(select) - - # Return - return - - # Unit Test time selection function -------------------------------------------- + # Unit Test time selection function ----------------------------------------------------------------------- def _test_time_selection(self): """ Unit Test time selection @@ -376,7 +359,7 @@ class Test(test): # Return return - # Unit Test set ebounds function ----------------------------------------------------- + # Unit Test set ebounds function -------------------------------------------------------------------------- def _test_set_ebounds_usetresh_user(self): """ Unit Test set ebounds with USER usetresh @@ -450,6 +433,8 @@ class Test(test): self._teardown(select) + # Return + return # Unit Test for copy --------------------------------------------------------------------------------- def _test_copy(self): @@ -472,78 +457,10 @@ class Test(test): self._teardown(select) - - # Unit Test for ctselect copy - def _test_for_ctselect_copy(self): - """ - Unit Test for ctselect copy - - """ - select = self._setup(inobs=self._events,tmin=500.0,tmax=1000.0,emin=0.2,emax=80,outobs='ctselect_py1.fits',logfile='ctselect_py1.log') - - # Run ctselect tool - select.logFileOpen() # Make sure we get a log file - select.run() - select.save() - - # Copy ctselect tool - cpy_select = select.copy() - - # Check observation of ctselect copy - self._check_obs(cpy_select.obs(), 'ctselect copy') - - # Execute copy of ctselect tool again, now with a higher chatter - # level than before and without any selection. Since the tools - # still holds the same selected observation container from before - # the number of events will be identical. - cpy_select['ra'] = 'NONE' - cpy_select['dec'] = 'NONE' - cpy_select['rad'] = 'NONE' - cpy_select['tmin'] = 'NONE' - cpy_select['tmax'] = 'NONE' - cpy_select['emin'] = 'NONE' - cpy_select['emax'] = 'NONE' - cpy_select['outobs'] = 'ctselect_py2.fits' - cpy_select['logfile'] = 'ctselect_py2.log' - cpy_select['chatter'] = 3 - cpy_select['publish'] = True - cpy_select.logFileOpen() # Needed to get a new log file - cpy_select.execute() - - # Check result file - self._check_result_file('ctselect_py2.fits','same selected obs container') - - # Execute again the copy of ctselect tool again, now using the pointing - # information in the input observation. We also set the minimum values - # to valid event selections, but since the maximum values are still - # 'NONE', no event selections should occur. - cpy_select['usepnt'] = True - cpy_select['tmin'] = 500.0 - cpy_select['emin'] = 0.2 - cpy_select['usethres'] = 'USER' - cpy_select['outobs'] = 'ctselect_py3.fits' - cpy_select['logfile'] = 'ctselect_py3.log' - cpy_select['chatter'] = 4 - cpy_select.logFileOpen() # Needed to get a new log file - cpy_select.execute() - - # Check result file - self._check_result_file('ctselect_py3.fits', 'max value still none') - - # Now clear copy of ctselect tool - cpy_select.clear() - - # Check that cleared ctselect tool holds no observations and events - self._check_obs(cpy_select.obs(),'cleared ctselect tool', nobs=0) - - - self._teardown(select) - # Return return - - - # Unit Test check_infile function --------------------------------------------------------------- + + # Unit Test check_infile function ------------------------------------------------------------------------------------ def _test_check_infile_invalid_event_file(self): """ Unit Test check_infile invalid event file @@ -722,7 +639,7 @@ class Test(test): select.save() # Check result file - self._check_result_file('ctselect_py_ExprSelection.fits', 'time selection',nevents=3) + self._check_result_file('ctselect_py_ExprSelection.fits', 'time selection',nevents=2) self._teardown(select) @@ -842,106 +759,220 @@ class Test(test): # Return return - - # Unit Test invalid phase value or string - def _test_invalid_phase_value_string(self): + def _test_phase_invalid_min_negative(self): """ - Unit Test invalid phase value or string + Unit Test invalid phase min value """ - select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='0.8:0.3',outobs='ctselect_py12.fits',logfile='ctselect_py12.log') - - # Run ctselect tool - select.logFileOpen() # Make sure we get a log file - select.execute() + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='-0.1:0.3',outobs='ctselect_py_PhaseMinNegative.fits',logfile='ctselect_py_PhaseMinNegative.log') # Test invalid minimum phase value self.test_try('Test invalid minimum phase value -0.1:0.3') try: - select['phase'] = '-0.1:0.3' - select['outobs'] = 'ctselect_py13.fits' - select['logfile'] = 'ctselect_py13.log' select.logFileOpen() select.execute() self.test_try_failure('Exception not thrown for "-0.1:0.3"') except ValueError: self.test_try_success() + + self._teardown(select) - # Test invalid minimum phase value - self.test_try('Test invalid minimum phase value 1.1:0.3') - try: - select['phase'] = '1.1:0.3' - select['outobs'] = 'ctselect_py14.fits' - select['logfile'] = 'ctselect_py14.log' - select.logFileOpen() - select.execute() - self.test_try_failure('Exception not thrown for "1.1:0.3"') - except ValueError: - self.test_try_success() + # Return + return + + def _test_phase_invalid_max_negative(self): + """ + Unit Test invalid phase max value - # Test invalid maximum phase value - self.test_try('Test invalid maximum phase value 0.1:-0.3') + """ + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='0.1:-0.3',outobs='ctselect_py_PhaseMaxNegative.fits',logfile='ctselect_py_PhaseMaxNegative.log') + + # Test invalid minimum phase value + self.test_try('Test invalid maximun phase value 0.1:-0.3') try: - select['phase'] = '0.1:-0.3' - select['outobs'] = 'ctselect_py15.fits' - select['logfile'] = 'ctselect_py15.log' select.logFileOpen() select.execute() self.test_try_failure('Exception not thrown for "0.1:-0.3"') except ValueError: self.test_try_success() + + self._teardown(select) - # Test invalid maximum phase value - self.test_try('Test invalid maximum phase value 0.1:1.1') + # Return + return + + def _test_phase_invalid_minsupmax(self): + """ + Unit Test invalid phase value min sup max + + """ + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='1.1:0.3',outobs='ctselect_py_PhaseMinSupMax.fits',logfile='ctselect_py_PhaseMinSupMax.log') + + # Test invalid minimum phase value + self.test_try('Test invalid phase value 1.1:0.3') try: - select['phase'] = '0.1:1.1' - select['outobs'] = 'ctselect_py16.fits' - select['logfile'] = 'ctselect_py16.log' select.logFileOpen() select.execute() - self.test_try_failure('Exception not thrown for "0.1:1.1"') + self.test_try_failure('Exception not thrown for "1.1:0.3"') except ValueError: self.test_try_success() + + self._teardown(select) + + # Return + return + + def _test_phase_invalid_missmin(self): + """ + Unit Test invalid phase missing min + + """ + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='0.1:',outobs='ctselect_py_PhaseMissMin.fits',logfile='ctselect_py_PhaseMissMin.log') - # Test invalid phase string - self.test_try('Test invalid phase string 0.1:') + # Test invalid minimum phase value + self.test_try('Test invalid phase value 0.1:') try: - select['phase'] = '0.1:' - select['outobs'] = 'ctselect_py17.fits' - select['logfile'] = 'ctselect_py17.log' select.logFileOpen() select.execute() self.test_try_failure('Exception not thrown for "0.1:"') except ValueError: self.test_try_success() + + self._teardown(select) + + # Return + return + + def _test_phase_invalid_missmax(self): + """ + Unit Test invalid phase missing max - # Test invalid phase string - self.test_try('Test invalid phase string :1.0') + """ + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase=':1.0',outobs='ctselect_py_PhaseMissMax.fits',logfile='ctselect_py_PhaseMissMax.log') + + # Test invalid minimum phase value + self.test_try('Test invalid phase value :1.0') try: - select['phase'] = ':1.0' - select['outobs'] = 'ctselect_py18.fits' - select['logfile'] = 'ctselect_py18.log' select.logFileOpen() select.execute() self.test_try_failure('Exception not thrown for ":1.0"') except ValueError: self.test_try_success() + + self._teardown(select) + + # Return + return + + def _test_phase_invalid_syntax(self): + """ + Unit Test invalid phase syntax - # Test invalid phase string - self.test_try('Test invalid phase string 0.1-1.0') + """ + select = self._setup(inobs=self._phased_events,rad=5,tmin='INDEF',tmax='INDEF',phase='0.1-1.0',outobs='ctselect_py_PhaseSyntax.fits',logfile='ctselect_py_PhaseSyntax.log') + + # Test invalid minimum phase value + self.test_try('Test invalid phase syntax :1.0') try: - select['phase'] = '0.1-1.0' - select['outobs'] = 'ctselect_py19.fits' - select['logfile'] = 'ctselect_py19.log' select.logFileOpen() select.execute() - self.test_try_failure('Exception not thrown for "0.1-1.0"') + self.test_try_failure('Exception not thrown for ":1.0"') except ValueError: self.test_try_success() - + self._teardown(select) # Return return + # Functionnal Test for ctselect ------------------------------------------------------------------------------------------------- + def _FuncTest_copy_none(self): + """ + Functionnal Test for ctselect copy and none + + """ + select = self._setup(inobs=self._events,tmin=500.0,tmax=1000.0,emin=0.2,emax=80,outobs='ctselect_py_CopyNone.fits',logfile='ctselect_py_CopyNone.log') + + # Run ctselect tool + select.logFileOpen() # Make sure we get a log file + select.run() + select.save() + + # Copy ctselect tool + cpy_select = select.copy() + + # Check observation of ctselect copy + self._check_obs(cpy_select.obs(), 'Functionnal Test for ctselect copy and none') + + # Execute copy of ctselect tool again, now with a higher chatter + # level than before and without any selection. Since the tools + # still holds the same selected observation container from before + # the number of events will be identical. + cpy_select['ra'] = 'NONE' + cpy_select['dec'] = 'NONE' + cpy_select['rad'] = 'NONE' + cpy_select['tmin'] = 'NONE' + cpy_select['tmax'] = 'NONE' + cpy_select['emin'] = 'NONE' + cpy_select['emax'] = 'NONE' + cpy_select['outobs'] = 'ctselect_py_SameCont.fits' + cpy_select['logfile'] = 'ctselect_py_SameCont.log' + cpy_select['chatter'] = 3 + cpy_select['publish'] = True + cpy_select.logFileOpen() # Needed to get a new log file + cpy_select.execute() + + # Check result file + self._check_result_file('ctselect_py_SameCont.fits','same selected obs container') + + # Execute again the copy of ctselect tool again, now using the pointing + # information in the input observation. We also set the minimum values + # to valid event selections, but since the maximum values are still + # 'NONE', no event selections should occur. + cpy_select['usepnt'] = True + cpy_select['tmin'] = 500.0 + cpy_select['emin'] = 0.2 + cpy_select['usethres'] = 'USER' + cpy_select['outobs'] = 'ctselect_py_MaxStillNone.fits' + cpy_select['logfile'] = 'ctselect_py_MaxStillNone.log' + cpy_select['chatter'] = 4 + cpy_select.logFileOpen() # Needed to get a new log file + cpy_select.execute() + + # Check result file + self._check_result_file('ctselect_py_MaxStillNone.fits', 'max value still none') + + # Now clear copy of ctselect tool + cpy_select.clear() + + # Check that cleared ctselect tool holds no observations and events + self._check_obs(cpy_select.obs(),'cleared ctselect tool', nobs=0) + + + self._teardown(select) + + # Return + return + + # Functionnal Test with randoms parameters + def _Functest_with_parameters(self): + """ + Unit Test with parameters + + """ + select = self._setup(inobs=self._events,tmin=500.0,tmax=1000.0,emin=0.2,emax=80,outobs='ctselect_py_FuncParam.fits',logfile='ctselect_py_FuncParam.log') + + # Run ctselect tool + select.logFileOpen() # Make sure we get a log file + select.run() + select.save() + + # Check result file + self._check_result_file('ctselect_py_FuncParam.fits', 'with parameters') + + + self._teardown(select) + + # Return + return \ No newline at end of file -- libgit2 0.21.4