casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_viewer.py
Go to the documentation of this file.
00001 import os
00002 import sys
00003 import shutil
00004 import subprocess
00005 from __main__ import default
00006 from tasks import *
00007 from taskinit import *
00008 import unittest
00009 
00010 '''
00011 Unit tests for task viewer. It tests the following parameters:
00012     infile:        image to load
00013     displaytype:   how the image should be displayed
00014     channel:       which channel of the cube should be displayed
00015     outdpi:        resolution of the output
00016     gui:           no gui should be displayed
00017 '''
00018 class viewer_test1(unittest.TestCase):
00019 
00020     # Input and output names
00021     img = 'test_image'
00022 
00023     def setUp(self):
00024         self.res = None
00025         self.chksum = None
00026         self.uname = os.uname()[0]
00027         if self.uname == 'Linux' :
00028             self.chksum = '/usr/bin/md5sum'
00029         elif self.uname == 'Darwin' :
00030             self.chksum = '/sbin/md5'
00031         if self.chksum is None or not os.path.exists(self.chksum) :
00032             raise RuntimeError("no md5 checksum program is available")
00033         default(viewer)
00034         if (os.path.exists(self.img)):
00035             os.system('rm -rf ' + self.img)
00036             
00037         datapath = os.environ.get('CASAPATH').split()[0] + '/data/demo/Images/'
00038         shutil.copytree(datapath+self.img, self.img)
00039     
00040     def tearDown(self):
00041         if (os.path.exists(self.img)):
00042             os.system('rm -rf ' + self.img)
00043             #os.system('rm -f test??.png')
00044 
00045     def getchecksum(self,img):
00046         if self.uname == 'Linux' :
00047             proc = subprocess.Popen(self.chksum + ' ' + img,stdout=subprocess.PIPE,shell=True)
00048             outstr = repr(proc.communicate()[0]).split()[0]
00049             return outstr.split("'")[1]
00050         elif self.uname == 'Darwin' :
00051             proc = subprocess.Popen(self.chksum + ' ' + img,stdout=subprocess.PIPE,shell=True)
00052             outstr = repr(proc.communicate()[0]).split()
00053             last_element = outstr[len(outstr)-1].split('\\')
00054             return last_element[0]
00055         return None
00056 
00057     def test1(self):
00058         '''Viewer 1: create png (default size, channel 0)'''
00059         outfile='test01.png'
00060         viewer(infile=self.img,outfile=outfile,gui=False)
00061         self.assertEqual(self.getchecksum(outfile),'e55d704ed0694d59dbf1fb0c01f299f8')
00062         
00063     def test2(self):
00064         '''Viewer 2: create png (default size, channel 3)'''
00065         outfile='test02.png'
00066         viewer(infile=self.img,outfile=outfile,channel=3,gui=False)
00067         self.assertEqual(self.getchecksum(outfile),'76ed16f68ca216a8dd34c0409fed554c')
00068 
00069     def test3(self):
00070         '''Viewer 3: create png (default size, channel 3, zoom=2)'''
00071         outfile='test03.png'
00072         viewer(infile=self.img,outfile=outfile,channel=3,zoom=2,gui=False)
00073         self.assertEqual(self.getchecksum(outfile),'994937a15c8e0949bf640aa575a04bd7')
00074         
00075     def test4(self):
00076         '''Viewer 4: create png (default size, channel 3, outscale=3)'''
00077         outfile='test04.png'
00078         viewer(infile=self.img,outfile=outfile,channel=3,outscale=3.0,gui=False)
00079         self.assertEqual(self.getchecksum(outfile),'1cc14fc0a82deb87755b5f45c0dcc352')
00080         
00081 
00082 def suite():
00083     ## test requires X11 virtual frame buffer...
00084     if os.uname()[0] != 'Darwin' :
00085         return [viewer_test1]
00086     else:
00087         return [ ]
00088