00001 import os
00002 import sys
00003 import shutil
00004 import listing as lt
00005 from __main__ import default
00006 from tasks import *
00007 from taskinit import *
00008 import unittest
00009
00010 '''
00011 Unit tests for task listvis. It tests the following parameters:
00012 vis: wrong and correct values
00013 datacolumn default and non-default values
00014 field: wrong field type; non-default value
00015 spw: wrong value; non-default value
00016 selectdata: True; subparameters:
00017 antenna: non-default values
00018
00019 '''
00020
00021 datapath = os.environ.get('CASAPATH').split()[0] + '/data/regression/unittest/listvis/'
00022
00023
00024 testmms = False
00025 if os.environ.has_key('TEST_DATADIR'):
00026 DATADIR = str(os.environ.get('TEST_DATADIR'))+'/listvis/'
00027 if os.path.isdir(DATADIR):
00028 testmms = True
00029 datapath = DATADIR
00030 else:
00031 print 'WARN: directory '+DATADIR+' does not exist'
00032
00033 print 'listvis tests will use data from '+datapath
00034
00035
00036 reffile = datapath+'reflistvis'
00037
00038
00039 msfile1 = 'ngc5921_ut.ms'
00040 msfile2 = 'OrionS_rawACSmod'
00041 if testmms:
00042 msfile2 = 'OrionS_rawACSmod.mms'
00043
00044 msfile3 = 'as1039q4_ut.ms'
00045 out = 'listvis'
00046
00047 class listvis_test1(unittest.TestCase):
00048
00049 def setUp(self):
00050 fpath = os.path.join(datapath, msfile1)
00051 os.symlink(fpath, msfile1)
00052
00053 fpath = os.path.join(datapath, msfile2)
00054 os.symlink(fpath, msfile2)
00055
00056 fpath = os.path.join(datapath, msfile3)
00057 os.symlink(fpath, msfile3)
00058
00059 default(listvis)
00060
00061
00062 def tearDown(self):
00063 if os.path.lexists(msfile1):
00064 os.unlink(msfile1)
00065 if os.path.lexists(msfile2):
00066 os.unlink(msfile2)
00067 if os.path.lexists(msfile3):
00068 os.unlink(msfile3)
00069
00070 os.system('rm -rf ' + out+'*')
00071 os.system('rm -rf ' + 'compare*')
00072
00073
00074 def test1(self):
00075 '''Listvis 1: Data column'''
00076 output = out+'1'
00077 comp = 'compare.1'
00078 reference = reffile+'1'
00079 listvis(vis=msfile1,datacolumn='data',listfile=output,
00080 field='2',spw='0:4~5',selectdata=True,antenna='8&9')
00081
00082 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00083 'New and reference files are different. %s != %s. '
00084 'See the diff file'%(output,reference))
00085 def test2(self):
00086 '''Listvis 2: Data column with different selections'''
00087 output = out+'2'
00088 comp = 'compare.2'
00089 reference = reffile+'2'
00090 listvis(vis=msfile1,field='0',spw='0:1~2',selectdata=True, antenna='2&11',
00091 listfile=output)
00092 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00093 'New and reference files are different. %s != %s. '
00094 'See the diff file'%(output,reference))
00095
00096 def test3(self):
00097 '''Listvis 3: Float data column (CAS-2138)'''
00098 output = out+'3'
00099 comp = 'compare.3'
00100 reference = reffile+'3'
00101 listvis(vis=msfile2,datacolumn='float_data',listfile=output,
00102 spw='0:2001~2003')
00103 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00104 'New and reference files are different. %s != %s. '
00105 'See the diff file.'%(output,reference))
00106
00107
00108 def test4(self):
00109 '''Listvis 4: Data with auto-correlation'''
00110 output = out+'4'
00111 comp = 'compare.4'
00112 reference = reffile+'4'
00113 listvis(vis=msfile1,datacolumn='data',listfile=output,
00114 spw='0:1',field='1',selectdata=True,antenna='2&&2')
00115 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00116 'New and reference files are different. %s != %s. '
00117 'See the diff file.'%(output,reference))
00118
00119 def test5(self):
00120 '''Listvis 5: MS with blanked scan (CAS-2112)'''
00121 output = out+'5'
00122 comp = 'compare.5'
00123 reference = reffile+'5'
00124 listvis(vis=msfile3,datacolumn='data',listfile=output,spw='0:1~2',
00125 selectdata=True,antenna='1',scan='1')
00126 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00127 'New and reference files are different. %s != %s. '
00128 'See the diff file.'%(output,reference))
00129
00130 def test6(self):
00131 '''Listvis 6: MS with good scan (CAS-2112)'''
00132 output = out+'6'
00133 comp = 'compare.6'
00134 reference = reffile+'6'
00135 listvis(vis=msfile3,spw='4:1~2',selectdata=True,antenna='8',scan='3',listfile=output)
00136 self.assertTrue(lt.runTests(output,reference,'1.000',comp),
00137 'New and reference files are different. %s != %s. '
00138 'See the diff file.'%(output,reference))
00139
00140
00141 def suite():
00142 return [listvis_test1]