00001
00002
00003
00004
00005
00006
00007
00008 import os
00009 import sys
00010 import shutil
00011 import glob
00012 from __main__ import default
00013 from tasks import *
00014 from taskinit import *
00015 import unittest
00016
00017 myname = 'test_conjugatevis'
00018
00019
00020 msname = 'conjugated.ms'
00021
00022 def checktable(thename, theexpectation):
00023 global msname, myname
00024 tb.open(msname+"/"+thename)
00025 if thename == "":
00026 thename = "MAIN"
00027 for mycell in theexpectation:
00028 print myname, ": comparing ", mycell
00029 value = tb.getcell(mycell[0], mycell[1])
00030
00031 try:
00032 isarray = value.__len__
00033 except:
00034
00035
00036 if mycell[3] == 0:
00037 in_agreement = (value == mycell[2])
00038 else:
00039 in_agreement = ( abs(value - mycell[2]) < mycell[3])
00040 else:
00041
00042
00043 if mycell[3] == 0:
00044 in_agreement = (value == mycell[2]).all()
00045 else:
00046 try:
00047 in_agreement = (abs(value - mycell[2]) < mycell[3]).all()
00048 except:
00049 in_agreement = False
00050 if not in_agreement:
00051 print myname, ": Error in MS subtable", thename, ":"
00052 print " column ", mycell[0], " row ", mycell[1], " contains ", value
00053 print " expected value is ", mycell[2]
00054 tb.close()
00055 return False
00056 tb.close()
00057 print myname, ": table ", thename, " as expected."
00058 return True
00059
00060
00061
00062
00063
00064 class test_conjugatevis(unittest.TestCase):
00065
00066 def setUp(self):
00067 res = None
00068
00069 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/concat/input/'
00070 cpath = os.path.abspath(os.curdir)
00071 filespresent = sorted(glob.glob("*.ms"))
00072 os.chdir(datapath)
00073 mymsname = 'shortpart1.ms'
00074 if not mymsname in filespresent:
00075 print "Copying ", mymsname
00076 shutil.copytree(mymsname, cpath+'/'+mymsname)
00077 os.chdir(cpath)
00078
00079 default(conjugatevis)
00080
00081 def tearDown(self):
00082 shutil.rmtree(msname,ignore_errors=True)
00083
00084 def test1(self):
00085 '''Conjugatevis 1: '''
00086 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00087
00088 self.res = conjugatevis(vis='shortpart1.ms', spwlist=[5,7], outputvis=msname)
00089 self.assertEqual(self.res,None)
00090
00091 print myname, ": Success! Now checking output ..."
00092 mscomponents = set(["table.dat",
00093 "table.f0"
00094 ])
00095 for name in mscomponents:
00096 if not os.access(msname+"/"+name, os.F_OK):
00097 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00098 retValue['success']=False
00099 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00100 else:
00101 print myname, ": ", name, "present."
00102 print myname, ": MS exists. Try opening as MS ..."
00103 try:
00104 ms.open(msname)
00105 except:
00106 print myname, ": Error Cannot open MS table", tablename
00107 retValue['success']=False
00108 retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00109 else:
00110 ms.close()
00111 print myname, ": OK. Checking tables in detail ..."
00112 retValue['success']=True
00113
00114
00115 name = ""
00116
00117 expected = [
00118 ['DATA', 4000,
00119 [[-0.00426177-0.00387163j],
00120 [ 0.00058119+0.00283016j]],
00121 0.00000001]
00122 ]
00123 results = checktable(name, expected)
00124 if not results:
00125 retValue['success']=False
00126 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00127 expected = [
00128 ['DATA', 3000,
00129 [[ 0.00347826-0.00406267j],
00130 [ 0.00458098-0.00508398j]],
00131 0.00000001]
00132 ]
00133 results = checktable(name, expected)
00134 if not results:
00135 retValue['success']=False
00136 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00137
00138
00139 class conjugatevis_cleanup(unittest.TestCase):
00140 def setUp(self):
00141 pass
00142
00143 def tearDown(self):
00144 os.system('rm -rf *.ms')
00145
00146 def testrun(self):
00147 '''Conjugatevis: Cleanup'''
00148 pass
00149
00150 def suite():
00151 return [test_conjugatevis,conjugatevis_cleanup]
00152