casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_splattotable.py
Go to the documentation of this file.
00001 ##########################################################################
00002 # imfit_test.py
00003 #
00004 # Copyright (C) 2008, 2009
00005 # Associated Universities, Inc. Washington DC, USA.
00006 #
00007 # This script is free software; you can redistribute it and/or modify it
00008 # under the terms of the GNU Library General Public License as published by
00009 # the Free Software Foundation; either version 2 of the License, or (at your
00010 # option) any later version.
00011 #
00012 # This library is distributed in the hope that it will be useful, but WITHOUT
00013 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 # License for more details.
00016 #
00017 # You should have received a copy of the GNU Library General Public License
00018 # along with this library; if not, write to the Free Software Foundation,
00019 # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00020 #
00021 # Correspondence concerning AIPS++ should be adressed as follows:
00022 #        Internet email: aips2-request@nrao.edu.
00023 #        Postal address: AIPS++ Project Office
00024 #                        National Radio Astronomy Observatory
00025 #                        520 Edgemont Road
00026 #                        Charlottesville, VA 22903-2475 USA
00027 #
00028 # <author>
00029 # Dave Mehringer
00030 # </author>
00031 #
00032 # <summary>
00033 # Test suite for the CASA task splattotable
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 # <prerequisite>
00040 # <ul>
00041 #   <li> <linkto class="task_splattotable.py:description">splattotable</linkto> 
00042 # </ul>
00043 # </prerequisite>
00044 #
00045 # <etymology>
00046 # Test for the splattotable task
00047 # </etymology>
00048 #
00049 # <synopsis>
00050 # Test the splattotable task and the sl.splattotable() method upon which it is built.
00051 # </synopsis> 
00052 #
00053 # <example>
00054 #
00055 # This test runs as part of the CASA python unit test suite and can be run from
00056 # the command line via eg
00057 # 
00058 # `echo $CASAPATH/bin/casapy | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_splattotable[test1,test2,...]
00059 #
00060 # </example>
00061 #
00062 # <motivation>
00063 # To provide a test standard for the splattotable task to ensure
00064 # coding changes do not break the associated bits 
00065 # </motivation>
00066 #
00067 
00068 ###########################################################################
00069 import shutil
00070 import casac
00071 from tasks import *
00072 from taskinit import *
00073 from __main__ import *
00074 import unittest
00075 
00076 good_list = "list1.txt"
00077 bad_list = "list2.txt"
00078 
00079 def run_sttmethod(list, table):
00080     mysl = sltool()
00081     restool = mysl.splattotable(filenames=list, table=table)
00082     mysl.close()
00083     return restool
00084 
00085 def run_stttask(list, table):
00086     default(splattotable)
00087     return splattotable(filenames=list, table=table)
00088 
00089 
00090 class splattotable_test(unittest.TestCase):
00091     
00092     def setUp(self):
00093         datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/splattotable/'
00094         shutil.copy(datapath + good_list, good_list)
00095         shutil.copy(datapath + bad_list, bad_list)
00096 
00097     
00098     def tearDown(self):
00099         os.remove(good_list)
00100         os.remove(bad_list)
00101 
00102     def test_exceptions(self):
00103         """splattotable: Test various exception cases"""
00104         
00105         def testit(filenames, table):
00106             for i in [0,1]:
00107                 if (i==0):
00108                     self.assertRaises(Exception, run_sttmethod, filenames, table)
00109                 else:
00110                     self.assertEqual(run_stttask(filenames, table), None)
00111 
00112         # blank output table name
00113         testit("list1.txt", "")
00114         
00115         # bad list 
00116         testit("list2.txt", "myout");
00117         
00118         # unwritable table
00119         testit("list1.txt", "/myout");
00120         
00121 
00122     def test_good_list(self):
00123         """splattotable: Test converting a good list"""
00124         def testit(filenames, table):
00125             mytb = tbtool()
00126             for i in [0,1]:
00127                 table = table + str(i)
00128                 if (i==0):
00129                     newsl = run_sttmethod(filenames, table)
00130                 else:
00131                     newsl = run_stttask(filenames, table)
00132                 self.assertTrue(mytb.open(table))
00133             tb.done()
00134                     
00135         testit("list1.txt", "good_table")
00136       
00137 
00138 def suite():
00139     return [splattotable_test]