Commit 0ec3bdbbd4e8579c08e14bc632a67877b7845019

Authored by Simon Bonnefoy
Committed by Jürgen Knödlseder
1 parent 829068d5

test unit for the ctfindvar tool (#2713)

Showing 1 changed file with 73 additions and 41 deletions
test/test_ctfindvar.py 100644 → 100755
... ... @@ -70,7 +70,17 @@ class Test(test):
70 70 ctfindvar = self._tool('ctfindvar')
71 71  
72 72 # Setup ctfindvar command
73   - cmd = ctfindvar+' logfile="ctfindvar_cmd1.log" chatter=1'
  73 + cmd = ctfindvar+' inobs="'+self._events+'"'+\
  74 + ' logfile="ctfindvar_cmd1.log" chatter=1'+\
  75 + ' prefix=ctfindvar_test_ histtype=FITS'+\
  76 + ' tmin=NONE tmax=NONE tinterval=20'+\
  77 + ' emin=0.2 emax=1.1'+\
  78 + ' nxpix=200 nypix=200 binsz=0.05'+\
  79 + ' proj=CAR coordsys=CEL'+\
  80 + ' xref=83.63 yref=22.51'+\
  81 + ' xsrc=83.63 ysrc=22.51'+\
  82 + ' caldb=prod2 irf=South_0.5h'
  83 +
74 84  
75 85 # Check if execution was successful
76 86 self.test_value(self._execute(cmd), 0,
... ... @@ -87,50 +97,70 @@ class Test(test):
87 97 """
88 98 Test ctfindvar from Python
89 99 """
  100 + print "here in the python test"
90 101 # Allocate ctfindvar
91   - tool = ctools.ctfindvar()
92   -
93   - # Check that saving does not nothing
94   - tool['logfile'] = 'ctfindvar_py0.log'
95   - tool.logFileOpen()
96   - tool.save()
97   - self.test_assert(not os.path.isfile('ctfindvar_py0.fits'),
98   - 'Check that no FITS file has been created')
99   -
100   - # Check that clearing does not lead to an exception or segfault
101   - tool.clear()
102   -
103   - # Now set ctfindvar parameters
104   - tool['logfile'] = 'ctfindvar_py1.log'
105   - tool['chatter'] = 2
106   -
107   - # Run ctfindvar tool
108   - tool.logFileOpen()
109   - tool.run()
110   -
111   - # Check result
112   - self._check_result(tool)
113   -
114   - # Copy ctfindvar tool
115   - cpy_tool = tool.copy()
116   -
117   - # Check result
118   - self._check_result(cpy_tool)
119   -
120   - # Run copy of ctfindvar tool again
121   - cpy_tool['logfile'] = 'ctfindvar_py2.log'
122   - cpy_tool['chatter'] = 3
123   - cpy_tool.logFileOpen()
124   - cpy_tool.run()
125   -
126   - # Check result
127   - self._check_result(cpy_tool)
  102 + ctfindvar = ctools.ctfindvar()
  103 +
  104 + #setup ctfindvar
  105 + ctfindvar['inobs'] = self._events
  106 + ctfindvar['logfile'] = 'ctfindvar_py0.log'
  107 + ctfindvar['chatter'] = 1
  108 + ctfindvar['prefix'] = 'ctfindvar_test_'
  109 + ctfindvar['histtype'] = 'FITS'
  110 + ctfindvar['tmin'] = 'NONE'
  111 + ctfindvar['tmax'] = 'NONE'
  112 + ctfindvar['tinterval'] = 20
  113 + ctfindvar['emin'] = 0.2
  114 + ctfindvar['emax'] = 1.1
  115 + ctfindvar['nxpix'] = 200
  116 + ctfindvar['nypix'] = 200
  117 + ctfindvar['binsx'] = 0.05
  118 + ctfindvar['xref'] = 83.63
  119 + ctfindvar['yref'] = 22.51
  120 + ctfindvar['xsrc'] = 83.63
  121 + ctfindvar['ysrc'] = 22.51
  122 + ctfindvar['caldb'] = 'prod2'
  123 + ctfindvar['irf'] = 'South_0.5h'
  124 +
  125 + ## Check that saving does not nothing
  126 + #ctfindvar['logfile'] = 'ctfindvar_py0.log'
  127 + #ctfindvar.logFileOpen()
  128 + #ctfindvar.save()
  129 + #self.test_assert(not os.path.isfile('ctfindvar_test_srcsig.fits'),
  130 + # 'Check that no FITS file has been created')
  131 +
  132 +
  133 + ## Run ctfindvar tool
  134 + #ctfindvar.logFileOpen()
  135 + ctfindvar.run()
  136 +
  137 + ## Check result
  138 + #self._check_result('ctfindvar_test_varsrcsig.fits')
  139 +
  140 + ## Copy ctfindvar tool
  141 + #cpy_tool = ctfindvar.copy()
  142 +
  143 + ## Check result
  144 + #self._check_result('ctfindvar_test_srcsig.fits')
  145 +
  146 + ## Run copy of ctfindvar tool again
  147 + #cpy_tool['logfile'] = 'ctfindvar_py2.log'
  148 + #cpy_tool['chatter'] = 3
  149 + #cpy_tool['prefix'] = 'ctfindvar_copytool_'
  150 + #cpy_tool.logFileOpen()
  151 + #cpy_tool.run()
  152 +
  153 + ## Check result
  154 + #self._check_result('ctfindvar_copytool_srcsig.fits')
  155 +
  156 + ## Check that clearing does not lead to an exception or segfault
  157 + #ctfindvar.clear()
128 158  
129 159 # Return
130 160 return
131 161  
132 162 # Check ctfindvar result
133   - def _check_result(self, tool):
  163 + def _check_result(self, filename):
134 164 """
135 165 Check content of tool
136 166  
... ... @@ -139,7 +169,9 @@ class Test(test):
139 169 tool : `~ctools.ctfindvar`
140 170 ctfindvar instance
141 171 """
142   - # TODO: Implement test on tool result
143   -
  172 + # Read variability file
  173 + #fits = gammalib.GFits(filename)
  174 + #self.test_value(fits.size(), 3,
  175 + # 'Check for 3 rows in srcsig file')
144 176 # Return
145 177 return
... ...