casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_listhistory.py
Go to the documentation of this file.
00001 import os
00002 import io
00003 import sys
00004 import shutil
00005 import commands
00006 from __main__ import default
00007 from tasks import *
00008 from taskinit import *
00009 import unittest
00010 
00011 datapath = os.environ.get('CASAPATH').split()[0] +\
00012                             '/data/regression/unittest/listhistory/'
00013 
00014 testmms = False
00015 if os.environ.has_key('TEST_DATADIR'):   
00016     DATADIR = str(os.environ.get('TEST_DATADIR'))+'/listhistory/'
00017     if os.path.isdir(DATADIR):
00018         testmms = True
00019         datapath = DATADIR
00020     else:
00021         print 'WARN: directory '+DATADIR+' does not exist'
00022 
00023 print 'listhistory tests will use data from '+datapath         
00024 
00025 class listhistory_test(unittest.TestCase):
00026 
00027     # Input and output names
00028     msfile = 'Itziar.ms'
00029     itismms = testmms
00030 
00031     def setUp(self):
00032         fpath = os.path.join(datapath,self.msfile)
00033         if os.path.lexists(fpath):
00034             os.symlink(fpath, self.msfile)
00035         else:
00036             self.fail('Data does not exist -> '+fpath)
00037             
00038     def tearDown(self):
00039         if os.path.lexists(self.msfile):
00040             os.unlink(self.msfile)
00041         
00042     def test1(self):
00043         '''Test 1: Empty input should return False'''
00044         myms = ''
00045         res = listhistory(myms)
00046         self.assertFalse(res)
00047         
00048     def test2(self):
00049         '''Test 2: Good input should return None'''
00050         res = listhistory(self.msfile)
00051         self.assertEqual(res,None)
00052         
00053     def test3(self):
00054         '''Test 3: Compare length of reference and new lists'''
00055         logfile= "mylisth.log"
00056         newfile= "newlisth.log"
00057         open(logfile,"w").close
00058         casalog.setlogfile(logfile)
00059         
00060         res = listhistory(self.msfile)
00061         cmd="sed -n \"/Begin Task/,/End Task/p\" %s > %s " %(logfile,newfile)
00062         os.system(cmd)
00063     
00064         # Get the number of lines in file
00065         refnum=13
00066         if self.itismms:
00067             refnum = 37
00068 
00069         cmd="wc -l %s |egrep \"[0-9]+\" -o" %newfile    
00070         output=commands.getoutput(cmd)
00071         num = int(output)
00072         self.assertEqual(refnum,num)
00073 
00074 
00075 class listhistory_cleanup(unittest.TestCase):
00076     
00077     def tearDown(self):
00078         os.system('rm -rf *Itziar.*')
00079 
00080     def test_cleanup(self):
00081         '''listhistory: Cleanup'''
00082         pass
00083         
00084 def suite():
00085     return [listhistory_test, listhistory_cleanup]
00086 
00087                
00088         
00089