Commits
clreynol authored 57b60573c5c
1 + | ######################################################################## |
2 + | # test_req_task_imhistory.py |
3 + | # |
4 + | # Copyright (C) 2018 |
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 + | # [Add the link to the JIRA ticket here once it exists] |
18 + | # |
19 + | # Based on the requirements listed in plone found here: |
20 + | # https://casa.nrao.edu/casadocs-devel/stable/global-task-list/task_imhistory/about |
21 + | # |
22 + | # |
23 + | ########################################################################## |
24 + | |
25 + | CASA6 = False |
26 + | try: |
27 + | import casatools |
28 + | from casatasks import imhistory, casalog |
29 + | CASA6 = True |
30 + | except ImportError: |
31 + | from __main__ import default |
32 + | from tasks import * |
33 + | from taskinit import * |
34 + | import sys |
35 + | import os |
36 + | import unittest |
37 + | import shutil |
38 + | import casaTestHelper |
39 + | |
40 + | if CASA6: |
41 + | casaimagepath = casatools.ctsys.resolve('images/ngc5921.clean.image') |
42 + | fitspath = casatools.ctsys.resolve('fits/1904-66_AIR.fits') |
43 + | miriadpath = casatools.ctsys.resolve('visibilities/other/compact.vis') |
44 + | else: |
45 + | if os.path.exists(os.environ.get('CASAPATH').split()[0] + '/data/casa-data-req'): |
46 + | dataroot = os.environ.get('CASAPATH').split()[0] + '/' |
47 + | casaimagepath = os.environ.get('CASAPATH').split()[0] + '/data/casa-data-req/image/ngc5921.clean.image' |
48 + | fitspath = os.environ.get('CASAPATH').split()[0] + '/data/casa-data-req/fits/1904-66_AIR.fits' |
49 + | else: |
50 + | dataroot = os.environ.get('CASAPATH').split()[0] + '/' |
51 + | casaimagepath = os.environ.get('CASAPATH').split()[0] + '/casa-data-req/image/ngc5921.clean.image' |
52 + | fitspath = os.environ.get('CASAPATH').split()[0] + '/casa-data-req/fits/1904-66_AIR.fits' |
53 + | |
54 + | logpath = casalog.logfile() |
55 + | |
56 + | class imhistory_test(unittest.TestCase): |
57 + | |
58 + | def setUp(self): |
59 + | if not CASA6: |
60 + | default(imhistory) |
61 + | else: |
62 + | pass |
63 + | |
64 + | def tearDown(self): |
65 + | casalog.setlogfile(logpath) |
66 + | if os.path.exists('testlog.log'): |
67 + | os.remove('testlog.log') |
68 + | |
69 + | def test_takesCASAImage(self): |
70 + | ''' 1. test_takesCASAImage: Check that imhistory takes a CASA image file (*.image)''' |
71 + | casalog.setlogfile('testlog.log') |
72 + | messages = imhistory(casaimagepath, mode='list', verbose=False) |
73 + | self.assertTrue(messages) |
74 + | |
75 + | def test_takesFITS(self): |
76 + | ''' 2. test_takesFITS: Check that imhistory takes a FITS file ''' |
77 + | casalog.setlogfile('testlog.log') |
78 + | messages = imhistory(fitspath, mode='list', verbose=False) |
79 + | self.assertTrue(messages) |
80 + | |
81 + | def test_listModeVerbose(self): |
82 + | ''' 3. test_listModeVerbose: Check that the list mode with verbose on outputs to log file |
83 + | and outputs an array of strings ''' |
84 + | casalog.setlogfile('testlog.log') |
85 + | historyMessages = imhistory(casaimagepath, mode='list', verbose=True) |
86 + | self.assertTrue(len(historyMessages) > 0 and 'HISTORY' in open('testlog.log').read()) |
87 + | |
88 + | def test_listModeNoVerbose(self): |
89 + | ''' 4. test_listModeNoVerbose: Check that the list mode with verbose off outputs an array |
90 + | of strings and does not output to the log file ''' |
91 + | casalog.setlogfile('testlog.log') |
92 + | historyMessages = imhistory(casaimagepath, mode='list', verbose=False) |
93 + | self.assertFalse('HISTORY' in open('testlog.log').read()) |
94 + | |
95 + | def test_appendModeNoDefaults(self): |
96 + | '''5. test_appendModeNoDefaults: Check that the append mode adds a string to the image history |
97 + | without use of default settings for message or origin ''' |
98 + | casalog.setlogfile('testlog.log') |
99 + | success = imhistory(casaimagepath, mode='append', message='TESTMESSAGEtest5', origin='TESTORIGINtest5') |
100 + | |
101 + | imhistory(casaimagepath, mode='list', verbose=True) |
102 + | self.assertTrue('TESTMESSAGEtest5' in open('testlog.log').read() and 'TESTORIGINtest5' in open('testlog.log').read()) |
103 + | |
104 + | def test_appendModeDefaultOrigin(self): |
105 + | ''' 6. test_appendModeDefaultOrigin: Check that append mode adds a string to the image history with |
106 + | the default origin setting ''' |
107 + | casalog.setlogfile('testlog.log') |
108 + | default(imhistory) |
109 + | success = imhistory(casaimagepath, mode='append', message='TESTMESSAGEtest6') |
110 + | |
111 + | imhistory(casaimagepath, mode='list', verbose=True) |
112 + | self.assertTrue('imhistory' in open('testlog.log').read() and 'TESTMESSAGEtest6' in open('testlog.log').read()) |
113 + | |
114 + | def test_correctReturnedParameters(self): |
115 + | ''' 7. test_correctReturnedParameters: Check that imhistory returns the expected parameters by looking |
116 + | for FILLM and BPASS ''' |
117 + | casalog.setlogfile('testlog.log') |
118 + | historyMessages = imhistory(casaimagepath, mode='list') |
119 + | self.assertTrue(('FILLM' in s for s in historyMessages) and ('BPASS' in n for n in historyMessages)) |
120 + | |
121 + | def suite(): |
122 + | return[imhistory_test] |
123 + | |
124 + | # Main # |
125 + | if __name__ == '__main__': |
126 + | unittest.main() |
127 + | |
128 + | |
129 + | |
130 + | |
131 + |