######################################################################### # test_task_gencal.py # Copyright (C) 2018 # Associated Universities, Inc. Washington DC, USA. # # This script is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # This library is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public # License for more details. # # # Based on the requirements listed in casadocs found here: # https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.gencal.html # ########################################################################## import os import shutil import unittest from unittest.mock import patch import numpy as np from casatestutils import testhelper as th from casatasks import appendantab from casatools import ctsys, table tb = table() datapath = ctsys.resolve('/unittest/appendantab/') # input data evn_data = "evnData.ms" evn_antab = "evn.antab" append_data = "appendedData.ms" evn_ref = "evnRef.ms" data_copy = "dataCopy.ms" def compare_tsys(res, ref): # get all the cols from result tb.open(res + "/SYSCAL") res_cols = tb.colnames() # get all the cols from ref table #compare the two table return True class appendantab_test(unittest.TestCase): @classmethod def setUpClass(cls): pass def setUp(self): if os.path.exists(data_copy): shutil.rmtree(data_copy) shutil.copytree(os.path.join(datapath, evn_data), data_copy) def tearDown(self): if os.path.exists(data_copy): shutil.rmtree(data_copy) @classmethod def tearDownClass(cls): if os.path.exists(data_copy): shutil.rmtree(data_copy) def test_appendAll(self): """ Test appending both the GAIN_CURVE and SYSCAL tables """ appendantab(vis=data_copy, outvis=append_data, antab=evn_antab, overwrite=False, append_tsys=True, append_gc=True) # compare to ref syscal and gain_curve table self.assertTrue(th.compTables(append_data + "/SYSCAL", evn_ref + "/SYSCAL")) self.assertTrue(th.compTables(append_data + "/GAIN_CURVE", evn_ref + "/GAIN_CURVE")) def test_appendGainCurve(self): """ Test appending just the GAIN_CURVE table """ appendantab(vis=data_copy, outvis=append_data, antab=evn_antab, overwrite=False, append_tsys=False, append_gc=True) # make sure SYSCAL wasn't created self.assertFalse(os.path.exists(append_data + "/SYSCAL")) # compare to ref gain_curve table self.assertTrue(th.compTables(append_data + "/GAIN_CURVE", evn_ref + "/GAIN_CURVE")) def test_appendSysCal(self): """ Test appending just the SYSCAL table """ appendantab(vis=data_copy, outvis=append_data, antab=evn_antab, overwrite=False, append_tsys=True, append_gc=False) # make sure GAIN_CURVE wasn't created self.assertFalse(os.path.exists(append_data + "/GAIN_CURVE")) # compare to ref gain_curve table self.assertTrue(th.compTables(append_data + "/SYSCAL", evn_ref + "/SYSCAL")) def test_Overwrite(self): """ Test overwriting an existing table """ # Don't overwite the data on the first run appendantab(vis=data_copy, outvis=data_copy, antab=evn_antab, overwrite=False, append_tsys=True, append_gc=False) # No subtables should be created self.assertFalse(os.path.exists(append_data + "/SYSCAL")) self.assertFalse(os.path.exists(append_data + "/GAIN_CURVE")) # Second run with overwrite should create subtables appendantab(vis=data_copy, outvis=data_copy, antab=evn_antab, overwrite=True, append_tsys=True, append_gc=False) # Subtables should be created self.assertTrue(os.path.exists(append_data + "/SYSCAL")) self.assertTrue(os.path.exists(append_data + "/GAIN_CURVE")) if __name__ == '__main__': unittest.main()