casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_clearstat.py
Go to the documentation of this file.
00001 import os
00002 import sys
00003 import shutil
00004 from __main__ import default
00005 from tasks import *
00006 from taskinit import *
00007 import unittest
00008 
00009 '''
00010 Unit tests of task clearstat. It tests the following parameters:
00011     clears read lock on table,
00012     clears write lock on table,
00013     clears read lock on image,
00014     clears write lock on image,
00015     clears all locks
00016 '''
00017 
00018 class clearstat_test(unittest.TestCase):
00019     
00020     # Input names
00021     msfile = 'Itziar.ms'
00022     res = None
00023     img = 'n4826_tmom1.im'
00024     
00025     def setUp(self):
00026         self.res = None
00027         default('clearstat')
00028         
00029         if(os.path.exists(self.msfile)):
00030             os.system('rm -rf ' + self.msfile)
00031         if(os.path.exists(self.img)):
00032             os.system('rm -rf ' + self.img)
00033             
00034         shutil.copytree(os.environ.get('CASAPATH').split()[0] +\
00035                             '/data/regression/exportasdm/input/'+self.msfile, self.msfile)
00036             
00037         datapath = os.environ.get('CASAPATH').split()[0] + '/data/regression/ngc4826redux/reference/'
00038         shutil.copytree(datapath+self.img, self.img)
00039     
00040     def tearDown(self):
00041         os.system('rm -rf ' + self.msfile)
00042         os.system('rm -rf ' + self.img)
00043 
00044         tb.close()
00045         if(ia.isopen == True):
00046             ia.close()
00047             
00048         
00049     def test1(self):
00050         '''Test 1: Clear table read lock'''
00051         tb.open(self.msfile)
00052         lock = tb.haslock(write=False)
00053         self.assertTrue(lock,'Cannot acquire read lock on table')
00054         clearstat()
00055         lock = tb.haslock(write=False)
00056         tb.close()
00057         self.assertFalse(lock,'Failed to clear table read lock')
00058 
00059     def test2(self):
00060         '''Test 2: Clear table write lock'''
00061         tb.open(self.msfile)
00062         tb.lock()
00063         lock = tb.haslock(write=True)
00064         self.assertTrue(lock,'Cannot acquire write lock on table')
00065         clearstat()
00066         lock = tb.haslock(write=True)
00067         tb.close()
00068         self.assertFalse(lock,'Failed to clear table write lock')
00069 
00070     def test3(self):
00071         '''Test 3: Clear image read lock'''
00072         ia.open(self.img)
00073         lock = ia.haslock()
00074         self.assertTrue(lock[0]==True and lock[1]==False,'Cannot acquire read lock on image')
00075         clearstat()
00076         lock = ia.haslock()
00077         ia.close()
00078         self.assertTrue(lock[0]==False and lock[1]==False,'Failed to clear read lock on image')
00079 
00080     def test4(self):
00081         '''Test 4: Clear image write lock'''
00082         ia.open(self.img)
00083         ia.lock(writelock=True)
00084         lock = ia.haslock()
00085         self.assertTrue(lock[0]==True and lock[1]==True,'Cannot acquire write lock on image')
00086         clearstat()
00087         lock = ia.haslock()
00088         ia.close()
00089         self.assertTrue(lock[0]==False and lock[1]==False,'Failed to clear write lock on image')
00090 
00091     def test5(self):
00092         '''Test 5: Clear all locks'''
00093         tb.open(self.msfile)
00094         tbreadlock = tb.haslock(write=False)
00095         tb.lock()
00096         tbwritelock = tb.haslock(write=True)
00097         ia.open(self.img)
00098         ia.lock(writelock=True)
00099         lock = ia.haslock()
00100         self.assertTrue(tbreadlock==True and tbwritelock==True and lock[0]==True and lock[1]==True,
00101                         'Cannot acquire locks on table and/or image')
00102         clearstat()
00103         tbreadlock = tb.haslock(write=False)
00104         tbwritelock = tb.haslock(write=True)
00105         lock = ia.haslock()
00106         tb.close()
00107         ia.close()
00108 
00109         self.assertTrue(tbreadlock==False and tbwritelock==False and lock[0]==False and lock[1]==False,
00110                         'Failed to clear locks on table and/or image')
00111         
00112 
00113 
00114 def suite():
00115     return [clearstat_test]
00116     
00117     
00118