Commits

Takeshi Nakazato authored 123809dc75c
CAS-14347 rename some variables to avoid name conflict
No tags

casatasks/tests/scripts/test_casaxmlutil.py

Modified
11 11 import shutil
12 12 from typing import NamedTuple, Callable
13 13 import unittest
14 14
15 15 from casatasks import casalog, sdcal, sdfit
16 16 from casatasks.private.casaxmlutil import xml_constraints_injector
17 17 from casatools import ctsys
18 18
19 19 casalogpath = casalog.logfile()
20 20 testdir = 'cxutest'
21 -SUCCESS = True
22 -FAIL = False
23 21
24 22
25 23 class Testdata(NamedTuple):
26 24 """Testdatapath class."""
27 25
28 26 datapath: str
29 27 infiles: dict
30 28 tempfiles: dict
31 29
32 30
142 140
143 141 class SDCalTest(CasaxmlutilTest):
144 142 """Test the constraints of sdcal."""
145 143
146 144 testdata = Testdata(ctsys.resolve('unittest/sdcal'),
147 145 {'ps': 'uid___A002_X6218fb_X264.ms.sel',
148 146 'otf': 'uid___A002_X6218fb_X264.ms.sel.otfraster'},
149 147 {'outfile': 'sdcal.out',
150 148 'applyfile': 'apply.cal'})
151 149 task = sdcal
152 - success = SUCCESS
153 - fail = FAIL
150 + expect = True
151 + require = False
154 152
155 - def __test_sdcal(self, whether: bool, args: dict, desired: dict=None, prepare_data: bool=False):
153 + def __test_sdcal(self, expect_parameter_override: bool, args: dict, desired: dict=None, prepare_data: bool=False):
156 154 """Test sdcal with parameters, prepare input data if needed."""
157 155 if prepare_data:
158 156 self.task(infile=self.testdata.infiles['ps'], calmode='tsys',
159 157 outfile=self.testdata.tempfiles['applyfile'])
160 158 if not args.get('outfile'):
161 159 args['outfile'] = self.testdata.tempfiles['outfile']
162 - if whether is SUCCESS:
160 + if expect_parameter_override:
163 161 self.assertIsNotNone(desired)
164 162 self.positive_test(self.task, args, desired)
165 163 else:
166 164 self.negative_test(self.task, args)
167 165
168 166 def test_sdcal_ps(self):
169 167 """Test sdcal(calmode=ps)."""
170 - self.__test_sdcal(self.fail,
168 + self.__test_sdcal(self.require,
171 169 args={'infile': self.testdata.infiles['ps'],
172 170 'calmode': 'ps'})
173 171
174 172 def test_sdcal_otfraster(self):
175 173 """Test sdcal(calmode=otfraster)."""
176 - self.__test_sdcal(self.success,
174 + self.__test_sdcal(self.expect,
177 175 args={'infile': self.testdata.infiles['otf'],
178 176 'calmode': 'otfraster'},
179 177 desired={'intent': 'OBSERVE_TARGET#ON_SOURCE'})
180 178
181 179 def test_sdcal_otfraster_not_override(self):
182 180 """Test sdcal(calmode=otfraster, intent='..')."""
183 - self.__test_sdcal(self.fail,
181 + self.__test_sdcal(self.require,
184 182 args={'infile': self.testdata.infiles['otf'],
185 183 'calmode': 'otfraster',
186 184 'intent': 'OBSERVE_TARGET#ON_SOURCE'})
187 185
188 186 def test_sdcal_otf(self):
189 187 """Test sdcal(calmode=otf)."""
190 - self.__test_sdcal(self.success,
188 + self.__test_sdcal(self.expect,
191 189 args={'infile': self.testdata.infiles['otf'],
192 190 'calmode': 'otf'},
193 191 desired={'intent': 'OBSERVE_TARGET#ON_SOURCE'})
194 192
195 193 def test_sdcal_otf_not_override(self):
196 194 """Test sdcal(calmode=otf, intent='..')."""
197 - self.__test_sdcal(self.fail,
195 + self.__test_sdcal(self.require,
198 196 args={'infile': self.testdata.infiles['otf'],
199 197 'calmode': 'otf',
200 198 'intent': 'OBSERVE_TARGET#ON_SOURCE'})
201 199
202 200 def test_sdcal_apply(self):
203 201 """Test sdcal(calmode=apply)."""
204 - self.__test_sdcal(self.success,
202 + self.__test_sdcal(self.expect,
205 203 args={'infile': self.testdata.infiles['ps'],
206 204 'calmode': 'apply',
207 205 'applytable': self.testdata.tempfiles['applyfile']},
208 206 desired={'interp': ''},
209 207 prepare_data=True)
210 208
211 209 def test_sdcal_apply_not_override(self):
212 210 """Test sdcal(calmode=apply, interp='..')."""
213 - self.__test_sdcal(self.fail,
211 + self.__test_sdcal(self.require,
214 212 args={'infile': self.testdata.infiles['ps'],
215 213 'calmode': 'apply',
216 214 'applytable': self.testdata.tempfiles['applyfile'],
217 215 'interp': 'nearest'},
218 216 prepare_data=True)
219 217
220 218 def test_sdcal_ps_apply(self):
221 219 """Test sdcal(calmode=ps,apply)."""
222 - self.__test_sdcal(self.success,
220 + self.__test_sdcal(self.expect,
223 221 args={'infile': self.testdata.infiles['ps'],
224 222 'calmode': 'ps,apply'},
225 223 desired={'applytable': '',
226 224 'interp': ''})
227 225
228 226 def test_sdcal_ps_apply_not_override(self):
229 227 """Test sdcal(calmode=ps,apply) with applytabe and interp are not null."""
230 - self.__test_sdcal(self.fail,
228 + self.__test_sdcal(self.require,
231 229 args={'infile': self.testdata.infiles['ps'],
232 230 'calmode': 'ps,apply',
233 231 'applytable': self.testdata.tempfiles['applyfile'],
234 232 'interp': 'nearest'},
235 233 prepare_data=True)
236 234
237 235 def test_sdcal_tsys_apply(self):
238 236 """Test sdcal(calmode=tsys,apply)."""
239 - self.__test_sdcal(self.success,
237 + self.__test_sdcal(self.expect,
240 238 args={'infile': self.testdata.infiles['ps'],
241 239 'calmode': 'tsys,apply'},
242 240 desired={'applytable': '',
243 241 'interp': ''})
244 242
245 243 def test_sdcal_tsys_apply_not_override(self):
246 244 """Test sdcal(calmode=tsys,apply) with applytabe and interp are not null."""
247 - self.__test_sdcal(self.fail,
245 + self.__test_sdcal(self.require,
248 246 args={'infile': self.testdata.infiles['ps'],
249 247 'calmode': 'tsys,apply',
250 248 'applytable': self.testdata.tempfiles['applyfile'],
251 249 'interp': 'nearest'},
252 250 prepare_data=True)
253 251
254 252 def test_sdcal_ps_tsys_apply(self):
255 253 """Test sdcal(calmode=ps,tsys,apply)."""
256 - self.__test_sdcal(self.success,
254 + self.__test_sdcal(self.expect,
257 255 args={'infile': self.testdata.infiles['ps'],
258 256 'calmode': 'ps,tsys,apply'},
259 257 desired={'applytable': '',
260 258 'interp': ''})
261 259
262 260 def test_sdcal_ps_tsys_apply_not_override(self):
263 261 """Test sdcal(calmode=ps,tsys,apply) with applytabe and interp are not null."""
264 - self.__test_sdcal(self.fail,
262 + self.__test_sdcal(self.require,
265 263 args={'infile': self.testdata.infiles['ps'],
266 264 'calmode': 'ps,tsys,apply',
267 265 'applytable': self.testdata.tempfiles['applyfile'],
268 266 'interp': 'nearest'},
269 267 prepare_data=True)
270 268
271 269 def test_sdcal_otfraster_apply(self):
272 270 """Test sdcal(calmode=otfraster,apply)."""
273 - self.__test_sdcal(self.success,
271 + self.__test_sdcal(self.expect,
274 272 args={'infile': self.testdata.infiles['otf'],
275 273 'calmode': 'otfraster,apply'},
276 274 desired={'applytable': '',
277 275 'interp': '',
278 276 'intent': 'OBSERVE_TARGET#ON_SOURCE'})
279 277
280 278 def test_sdcal_otfraster_apply_not_override(self):
281 279 """Test sdcal(calmode=otfraster,apply) with applytabe/interp/intent are not null."""
282 - self.__test_sdcal(self.fail,
280 + self.__test_sdcal(self.require,
283 281 args={'infile': self.testdata.infiles['otf'],
284 282 'calmode': 'otfraster,apply',
285 283 'applytable': self.testdata.tempfiles['applyfile'],
286 284 'interp': 'nearest',
287 285 'intent': 'OBSERVE_TARGET#ON_SOURCE'},
288 286 prepare_data=True)
289 287
290 288 def test_sdcal_otfraster_tsys_apply(self):
291 289 """Test sdcal(calmode=otfraster,tsys,apply)."""
292 - self.__test_sdcal(self.success,
290 + self.__test_sdcal(self.expect,
293 291 args={'infile': self.testdata.infiles['otf'],
294 292 'calmode': 'otfraster,tsys,apply'},
295 293 desired={'applytable': '',
296 294 'interp': ''})
297 295
298 296 def test_sdcal_otfraster_tsys_apply_not_override(self):
299 297 """Test sdcal(calmode=otfraster,tsys,apply) with applytabe and interp are not null."""
300 - self.__test_sdcal(self.fail,
298 + self.__test_sdcal(self.require,
301 299 args={'infile': self.testdata.infiles['otf'],
302 300 'calmode': 'otfraster,tsys,apply',
303 301 'applytable': self.testdata.tempfiles['applyfile'],
304 302 'interp': 'nearest'},
305 303 prepare_data=True)
306 304
307 305 def test_sdcal_otf_tsys_apply(self):
308 306 """Test sdcal(calmode=otf,tsys,apply)."""
309 - self.__test_sdcal(self.success,
307 + self.__test_sdcal(self.expect,
310 308 args={'infile': self.testdata.infiles['otf'],
311 309 'calmode': 'otf,tsys,apply'},
312 310 desired={'applytable': '',
313 311 'interp': ''})
314 312
315 313 def test_sdcal_otf_tsys_apply_not_override(self):
316 314 """Test sdcal(calmode=otf,tsys,apply) with applytabe and interp are not null."""
317 - self.__test_sdcal(self.fail,
315 + self.__test_sdcal(self.require,
318 316 args={'infile': self.testdata.infiles['otf'],
319 317 'calmode': 'otf,tsys,apply',
320 318 'applytable': self.testdata.tempfiles['applyfile'],
321 319 'interp': 'nearest'},
322 320 prepare_data=True)
323 321
324 322
325 323 class SDFitTest(CasaxmlutilTest):
326 324 """Test the constraints of sdfit."""
327 325
328 326 testdata = Testdata(ctsys.resolve('unittest/sdfit'),
329 327 {'timebin': 'sdfit_tave.ms'},
330 328 {})
331 329
332 330 task = sdfit
333 - success = SUCCESS
334 - fail = FAIL
331 + expect = True
332 + require = False
335 333
336 - def __test_sdfit(self, whether: bool, args: dict, desired: dict=None):
334 + def __test_sdfit(self, expect_parameter_override: bool, args: dict, desired: dict=None):
337 335 """Test sdfit with arguments and desired output."""
338 - if whether is SUCCESS:
336 + if expect_parameter_override:
339 337 self.positive_test(self.task, args, desired)
340 338 else:
341 339 self.negative_test(self.task, args)
342 340
343 341 def test_sdfit_timebin(self):
344 342 """Test sdfit(timebin='1s'). If timebin is specified a value, then timespan is overridden by ''."""
345 - self.__test_sdfit(self.success,
343 + self.__test_sdfit(self.expect,
346 344 args={'infile': self.testdata.infiles['timebin'],
347 345 'datacolumn': 'float_data',
348 346 'nfit': [1], 'pol': 'XX',
349 347 'timebin': '1s'},
350 348 desired={'timespan': ''})
351 349
352 350 def test_sdfit_timebin_is_empty(self):
353 351 """Test sdfit(timebin='')."""
354 - self.__test_sdfit(self.fail,
352 + self.__test_sdfit(self.require,
355 353 args={'infile': self.testdata.infiles['timebin'],
356 354 'datacolumn': 'float_data',
357 355 'nfit': [1], 'pol': 'XX',
358 356 'timebin': ''})
359 357
360 358
361 359 import importlib
362 360 casashell = importlib.find_loader('casashell')
363 361 if casashell is not None:
364 362 from casashell.private.sdcal import sdcal as s_sdcal
365 363 from casashell.private.sdfit import sdfit as s_sdfit
366 364
367 365 class CasashellSDCalTest(SDCalTest):
368 366 """Test that all constraint applying processes of casatasks.private.sdcal are not executed."""
369 367
370 368 task = s_sdcal
371 - success = FAIL
369 + expect = False
372 370
373 371 class CasashellSDFitTest(SDFitTest):
374 372 """Test that all constraint applying processes of casatasks.private.sdfit are not executed."""
375 373
376 374 task = s_sdfit
377 - success = FAIL
375 + expect = False
378 376
379 377 else:
380 378 casalog.post('could not load tasks in casashell.private')
381 379
382 380
383 381 if __name__ == '__main__':
384 382 unittest.main()

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut