Commits

Bob Garwood authored 45a22d9d1e4
more files for CAS-12372

gcwrap/python/scripts/tests/test_predictcomp.py

Modified
1 1 from __future__ import absolute_import
2 2 from __future__ import print_function
3 3 import os
4 4 import shutil
5 -import testhelper as th
6 5 import numpy as np
7 -from __main__ import default
8 -from tasks import predictcomp
9 -from taskinit import *
10 6 import unittest
11 -import exceptions
12 7
8 +from casatasks.private.casa_transition import is_CASA6
9 +if is_CASA6:
10 + from casatools import ctsys
11 + from casatasks import predictcomp, casalog
12 +
13 + ctsys_resolve = ctsys.resolve
14 +else:
15 + from __main__ import default
16 + from tasks import predictcomp
17 + from taskinit import *
18 +
19 + dataRoot = os.path.join(os.environ.get('CASAPATH'.split()[0],'data'))
20 + def ctsys_resolve(apath):
21 + return os.path.join(dataRoot,apath)
13 22
14 23 ''' Python unit tests for the predictcomp task
15 24
16 25 - tests the following parameters:
17 26 objname: error for unsupported object vs supported object
18 27 non-visible case
19 28 standard: wrong standard vs correct standard
20 29 minfreq/maxfreq: wrong unit vs correct unit
21 30 output: check for the cl file
22 31 antennalist: use of the configuration file to plot 'observed' visibility
23 32 amplitudes vs uvdist. GUI is turned off.
24 33
25 34
26 35 '''
27 36
28 -datapath = os.environ.get('CASAPATH').split()[0] +\
29 - '/data/alma/simmos/'
37 +datapath = 'alma/simmos'
30 38
31 39
32 40 class predictcomp_test(unittest.TestCase):
33 41
34 42 def setUp(self):
35 43 self.res=None
36 - default(predictcomp)
44 + if not is_CASA6:
45 + default(predictcomp)
37 46
38 47 def tearDown(self):
39 48 #pass
40 49 os.system('rm -rf *.cl')
41 50
42 51
43 52 def test_default(self):
44 53 '''predictcomp: test defaults'''
45 - self.res=predictcomp()
46 - self.assertIsNone(self.res)
54 + if is_CASA6:
55 + # casatasks throw exceptions
56 + self.assertRaises(Exception,predictcomp)
57 + else:
58 + # CASA 5 tasks do not
59 + self.res=predictcomp()
60 + self.assertIsNone(self.res)
47 61
48 62 def test_invalid_objname(self):
49 63 '''predictcomp: invalid objname'''
50 - self.res=predictcomp(objname='Moon', minfreq='100GHz',maxfreq='120GHz')
51 - self.assertIsNone(self.res)
52 -
64 + if is_CASA6:
65 + # casatasks throw exceptions
66 + self.assertRaises(Exception, predictcomp, objname='Moon', minfreq='100GHz',maxfreq='120GHz')
67 + else:
68 + # CASA 5 tasks do not
69 + self.res=predictcomp(objname='Moon', minfreq='100GHz',maxfreq='120GHz')
70 + self.assertIsNone(self.res)
71 +
53 72 def test_valid_objname(self):
54 73 '''predictcomp: valid objname'''
55 74 self.res=predictcomp(objname='Titan', epoch='2017/09/01/00:00', minfreq='100GHz',maxfreq='120GHz',
56 75 standard='Butler-JPL-Horizons 2012')
57 76 print("type(self.res) = ",type(self.res))
58 77 self.assertTrue(type(self.res)==dict)
59 78 self.assertTrue(os.path.exists(self.res['clist']))
60 79
61 80 def test_invalid_freqrange(self):
62 - '''predictcomp: invalud freqrange'''
63 - self.res=predictcomp(objname='Titan', epoch='2017/09/01/00:00', minfreq='100',maxfreq='120')
64 - self.assertIsNone(self.res)
65 -
81 + '''predictcomp: invalid freqrange'''
82 + if is_CASA6:
83 + # casatasks throw exceptions
84 + self.assertRaises(Exception, predictcomp, objname='Titan', epoch='2017/09/01/00:00', minfreq='100', maxfreq='120' )
85 + else:
86 + # CASA 5 tasks do not
87 + self.res=predictcomp(objname='Titan', epoch='2017/09/01/00:00', minfreq='100',maxfreq='120')
88 + self.assertIsNone(self.res)
89 +
66 90 def test_predicted_visplot(self):
67 - '''predictcomp: generate visibility plot for a given array configuration'''
68 - self.res=predictcomp(objname='Titan', epoch='2017/09/01/00:00', minfreq='100GHz',maxfreq='120GHz',
69 - standard='Butler-JPL-Horizons 2012',antennalist=datapath+'alma.cycle5.1.cfg', showplot=False,savefig='visplot.png')
70 - self.assertTrue(type(self.res)==dict)
71 - self.assertTrue(os.path.exists(self.res['clist']))
72 - self.assertTrue(os.path.exists('visplot.png'))
91 + # no plotting in this part of casa, skip this test
92 + if is_CASA6:
93 + casalog.post('test_predicted_visplot SKIPPED: no plotting in this part of casa','INFO')
94 + else:
95 + '''predictcomp: generate visibility plot for a given array configuration'''
96 + self.res=predictcomp( objname='Titan', epoch='2017/09/01/00:00', minfreq='100GHz',
97 + maxfreq='120GHz', standard='Butler-JPL-Horizons 2012',
98 + antennalist=ctsys.resolve(os.path.join(datapath,'alma.cycle5.1.cfg')),
99 + showplot=False,savefig='visplot.png' )
100 + self.assertTrue(type(self.res)==dict)
101 + self.assertTrue(os.path.exists(self.res['clist']))
102 + self.assertTrue(os.path.exists('visplot.png'))
73 103
74 104 def test_valid_but_not_visible_objname(self):
75 105 '''predictcomp: valid but not visible objname'''
76 - self.res=predictcomp(objname='Mars', epoch='2018/09/01/00:00', minfreq='100GHz',maxfreq='120GHz',
77 - antennalist=datapath+'alma.cycle5.1.cfg',showplot=False)
78 - self.assertIsNone(self.res)
106 + if is_CASA6:
107 + # casatasks throw exceptions
108 + self.assertRaises( Exception, predictcomp, objname='Mars', epoch='2018/09/01/00:00', minfreq='100GHz', maxfreq='120GHz',
109 + antennalist=ctsys.resolve(os.path.join(datapath,'alma.cycle5.1.cfg')), showplot=False )
110 + else:
111 + # CASA 5 tasks do not
112 + self.res=predictcomp(objname='Mars', epoch='2018/09/01/00:00', minfreq='100GHz',maxfreq='120GHz',
113 + antennalist=datapath+'alma.cycle5.1.cfg',showplot=False)
114 + self.assertIsNone(self.res)
79 115
80 116 def suite():
81 117 return [predictcomp_test]
82 118
119 +if is_CASA6:
120 + if __name__ == '__main__':
121 + unittest.main()

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut