Source
xxxxxxxxxx
1
+
##########################################################################
2
+
# test_imview.py
3
+
#
4
+
# Copyright (C) 2017
5
+
# Associated Universities, Inc. Washington DC, USA.
6
+
#
7
+
# This script is free software; you can redistribute it and/or modify it
8
+
# under the terms of the GNU Library General Public License as published by
9
+
# the Free Software Foundation; either version 2 of the License, or (at your
10
+
# option) any later version.
11
+
#
12
+
# This library is distributed in the hope that it will be useful, but WITHOUT
13
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15
+
# License for more details.
16
+
#
17
+
# You should have received a copy of the GNU Library General Public License
18
+
# along with this library; if not, write to the Free Software Foundation,
19
+
# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20
+
#
21
+
# Correspondence concerning AIPS++ should be adressed as follows:
22
+
# Internet email: aips2-request@nrao.edu.
23
+
# Postal address: AIPS++ Project Office
24
+
# National Radio Astronomy Observatory
25
+
# 520 Edgemont Road
26
+
# Charlottesville, VA 22903-2475 USA
27
+
#
28
+
# <author>
29
+
# Darrell Schiebel
30
+
# </author>
31
+
#
32
+
# <summary>
33
+
# Minimal test of CASA viewer
34
+
# </summary>
35
+
#
36
+
# <reviewed reviwer="" date="" tests="" demos="">
37
+
# </reviewed
38
+
#
39
+
# <prerequisite>
40
+
# <ul>
41
+
# </ul>
42
+
# </prerequisite>
43
+
#
44
+
# <etymology>
45
+
# </etymology>
46
+
#
47
+
# <synopsis>
48
+
# </synopsis>
49
+
#
50
+
# <example>
51
+
# </example>
52
+
#
53
+
# <motivation>
54
+
# Because the viewer has no way to specify specific dimensions and because the size
55
+
# of the bitmaps that it produces are dependent on the dimensions of the viewer, it
56
+
# is difficult to create good tests to verify that the viewer works properly. As a
57
+
# result, this test only verifies that it produces the expected file.
58
+
# </motivation>
59
+
#
60
+
61
+
###########################################################################
62
+
import os
63
+
import shutil
64
+
import os.path
65
+
import unittest
66
+
from casatools import coordsys, image
67
+
from casaviewer import imview
68
+
69
+
class imview_test(unittest.TestCase):
70
+
71
+
@classmethod
72
+
def setUpClass(self):
73
+
"""creating test images"""
74
+
self.linim = "lin"+str(os.getpid())+".im"
75
+
self.outfiles = { }
76
+
for t in ['jpg', 'pdf', 'eps', 'ps', 'png', 'xbm', 'xpm', 'ppm']:
77
+
self.outfiles[t] = "lin"+str(os.getpid())+"."+t
78
+
local_cs = coordsys( )
79
+
local_ia = image( )
80
+
local_cs.addcoordinate(linear=2)
81
+
local_ia.fromshape(self.linim,[20,20],csys=local_cs.torecord( ))
82
+
xx = local_ia.getchunk( )
83
+
xx[9:19,:] = 1
84
+
local_ia.putchunk(xx)
85
+
local_ia.done( )
86
+
local_cs.done( )
87
+
88
+
@classmethod
89
+
def tearDownClass(self):
90
+
"""removing test images and outfiles"""
91
+
if os.path.exists(self.linim):
92
+
shutil.rmtree(self.linim)
93
+
for outfileType in self.outfiles:
94
+
thisOutfile = self.outfiles[outfileType]
95
+
if os.path.exists(thisOutfile):
96
+
os.system('rm -rf ' + thisOutfile)
97
+
98
+
def test_xbm(self):
99
+
"""Test production of Xbm file"""
100
+
imview(self.linim,out=self.outfiles['xbm'])
101
+
self.assertTrue(os.path.isfile(self.outfiles['xbm']),"viewer failed to produce an Xbm file")
102
+
103
+
def test_jpg(self):
104
+
"""Test production of JPEG file"""
105
+
imview(self.linim,out=self.outfiles['jpg'])
106
+
self.assertTrue(os.path.isfile(self.outfiles['jpg']),"viewer failed to produce an JPEG file")
107
+
108
+
def test_pdf(self):
109
+
"""Test production of PDF file"""
110
+
imview(self.linim,out=self.outfiles['pdf'])
111
+
self.assertTrue(os.path.isfile(self.outfiles['pdf']),"viewer failed to produce an PDF file")
112
+
113
+
def test_eps(self):
114
+
"""Test production of EPS file"""
115
+
imview(self.linim,out=self.outfiles['eps'])
116
+
self.assertTrue(os.path.isfile(self.outfiles['eps']),"viewer failed to produce an EPS file")
117
+
118
+
def test_ps(self):
119
+
"""Test production of PS file"""
120
+
imview(self.linim,out=self.outfiles['ps'])
121
+
self.assertTrue(os.path.isfile(self.outfiles['ps']),"viewer failed to produce an PS file")
122
+
123
+
def test_xpm(self):
124
+
"""Test production of XPM file"""
125
+
imview(self.linim,out=self.outfiles['xpm'])
126
+
self.assertTrue(os.path.isfile(self.outfiles['xpm']),"viewer failed to produce an XPM file")
127
+
128
+
def test_ppm(self):
129
+
"""Test production of PPM file"""
130
+
imview(self.linim,out=self.outfiles['ppm'])
131
+
self.assertTrue(os.path.isfile(self.outfiles['ppm']),"viewer failed to produce an PPM file")
132
+
133
+
def test_png(self):
134
+
"""Test production of PNG file"""
135
+
imview(self.linim,out=self.outfiles['png'])
136
+
self.assertTrue(os.path.isfile(self.outfiles['png']),"viewer failed to produce an PNG file")
137
+
138
+
def suite():
139
+
return [imview_test]
140
+
141
+
if __name__ == '__main__':
142
+
unittest.main()