Go to the documentation of this file.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_createmultims'
00018
00019
00020 msname = 'multims.ms'
00021
00022 def checktable(thename, theexpectation):
00023 global msname, myname
00024 tb.open(msname+"/"+thename)
00025 for mycell in theexpectation:
00026 print myname, ": comparing ", mycell
00027 value = tb.getcell(mycell[0], mycell[1])
00028
00029 try:
00030 isarray = value.__len__
00031 except:
00032
00033
00034 if mycell[3] == 0:
00035 in_agreement = (value == mycell[2])
00036 else:
00037 in_agreement = ( abs(value - mycell[2]) < mycell[3])
00038 else:
00039
00040
00041 if mycell[3] == 0:
00042 in_agreement = (value == mycell[2]).all()
00043 else:
00044 try:
00045 in_agreement = (abs(value - mycell[2]) < mycell[3]).all()
00046 except:
00047 in_agreement = False
00048 if not in_agreement:
00049 print myname, ": Error in MS subtable", thename, ":"
00050 print " column ", mycell[0], " row ", mycell[1], " contains ", value
00051 print " expected value is ", mycell[2]
00052 tb.close()
00053 return False
00054 tb.close()
00055 print myname, ": table ", thename, " as expected."
00056 return True
00057
00058
00059
00060
00061
00062 class test_createmultims(unittest.TestCase):
00063
00064 def setUp(self):
00065 res = None
00066
00067 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/concat/input/'
00068 cpath = os.path.abspath(os.curdir)
00069 filespresent = sorted(glob.glob("part*.ms"))
00070 os.chdir(datapath)
00071 for mymsname in sorted(glob.glob("part*.ms")):
00072 if not mymsname in filespresent:
00073 print "Copying ", mymsname
00074 shutil.copytree(mymsname, cpath+'/'+mymsname)
00075 os.chdir(cpath)
00076
00077
00078 def tearDown(self):
00079 pass
00080 shutil.rmtree(msname,ignore_errors=True)
00081
00082 def test1(self):
00083 '''Test_createmultims 1: 4 parts, same sources but different spws'''
00084 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00085
00086 shutil.rmtree(msname,ignore_errors=True)
00087
00088 self.res = ms.createmultims(msname,
00089 ['part1.ms','part2.ms','part3.ms','part4.ms'],
00090 [],
00091 True,
00092 False,
00093 True)
00094 ms.close()
00095
00096 self.assertEqual(self.res,True)
00097
00098 ldict = listpartition(vis=msname, createdict=True)
00099
00100 self.assertEqual(sorted(ldict.keys()), [0, 1, 2, 3])
00101
00102 self.assertEqual(ldict[0]['MS'].split('/').pop(), 'part1.ms')
00103 self.assertEqual(ldict[1]['MS'].split('/').pop(), 'part2.ms')
00104 self.assertEqual(ldict[2]['MS'].split('/').pop(), 'part3.ms')
00105 self.assertEqual(ldict[3]['MS'].split('/').pop(), 'part4.ms')
00106
00107
00108 class testcreatemultims_cleanup(unittest.TestCase):
00109 def setUp(self):
00110 pass
00111
00112 def tearDown(self):
00113 pass
00114 os.system('rm -rf *.ms')
00115
00116 def testrun(self):
00117 '''Test_createmultims: Cleanup'''
00118 pass
00119
00120 def suite():
00121 return [test_createmultims,testcreatemultims_cleanup]
00122