Commits

Ville Suoranta authored 62d08243b33 Merge
Merge pull request #537 in CASA/casa6 from CAS-13777 to master

* commit '92130a29383d888994140690f779efb81155ae9d': Revert back the changes of test_exportuvfits to those of master to avoid conflicts with the new tests developed in CAS-12228. The tests in CAS-12228 already fix the tearDown problems. Cleanup the tearDown and also remove casa5 code in previous commit Fixed the tearDown to only remove the files copied or created by the test script. Fixed the tearDown of the test script to avoid deleting files that were not copied or created by the test script.

casatasks/tests/tasks/test_exportuvfits.py

Modified
3 3 import os
4 4 import shutil
5 5 import unittest
6 6 import math
7 7 import numpy as np
8 8 import numbers
9 9
10 10 try:
11 11 from casatools import ctsys, table, msmetadata
12 12 from casatasks import exportuvfits, importuvfits
13 +
13 14 _tb = table()
14 15 ctsys_resolve = ctsys.resolve
15 16 _msmd = msmetadata()
16 17 is_CASA6 = True
17 18 except ImportError:
18 19 from tasks import *
19 20 from taskinit import *
20 21 import casac
21 22 from __main__ import *
23 +
22 24 _tb = tbtool()
23 25 _msmd = msmdtool()
24 26 is_CASA6 = False
25 27 from casa_stack_manip import stack_frame_find
28 +
26 29 casa_stack_rethrow = stack_frame_find().get('__rethrow_casa_exceptions', False)
27 30
28 31 data_root = os.environ.get('CASAPATH').split()[0] + '/casatestdata/'
32 +
33 +
29 34 def ctsys_resolve(apath):
30 35 return os.path.join(data_root, apath)
31 36
32 37 datapath = 'unittest/exportuvfits/'
33 38
39 +
34 40 class exportuvfits_test(unittest.TestCase):
35 41
36 42 def setUp(self):
37 43 self.datapath = ctsys_resolve(datapath)
38 -
44 +
39 45 def tearDown(self):
40 46 self.assertTrue(len(_tb.showcache()) == 0)
41 47 # make sure directory is clean as per verification test requirement
42 48 cwd = os.getcwd()
43 49 for filename in os.listdir(cwd):
44 50 file_path = os.path.join(cwd, filename)
45 51 try:
46 52 if os.path.isfile(file_path) or os.path.islink(file_path):
47 53 os.unlink(file_path)
48 54 elif os.path.isdir(file_path):
49 55 # CASA 5 tests need this directory
50 56 if filename != 'xml':
51 57 shutil.rmtree(file_path)
52 58 except Exception as e:
53 59 print('Failed to delete %s. Reason: %s' % (file_path, e))
54 60
55 61 def test_export_overwrite(self):
56 62 """CAS-5492: test the overwrite parameter when exporting MSes to uvfits"""
57 - msname = "uvfits_test.ms"
63 + msname = "uvfits_test.ms"
58 64 shutil.copytree(os.path.join(self.datapath, msname), msname)
59 65 fitsname = "CAS-5492.uvfits"
60 66 res = exportuvfits(vis=msname, fitsfile=fitsname)
61 67 if is_CASA6:
62 68 # Not sure why all of a sudden CASA6 is returning None for tasks
63 69 self.assertTrue(res == None, "Failed exportuvfits")
64 70 else:
65 71 self.assertTrue(res, "Failed exportuvfits")
66 72 # fail because overwrite=False.
67 73 # CASA 6 throws an exception, CASA 5 returns False
68 74 if is_CASA6 or casa_stack_rethrow:
69 75 self.assertRaises(
70 76 Exception, exportuvfits, vis=msname, fitsfile=fitsname, overwrite=False,
71 77 msg="exportuvfits succeeded but should have failed because "
72 - + "overwrite=False"
78 + + "overwrite=False"
73 79 )
74 80 else:
75 81 self.assertFalse(
76 82 exportuvfits(vis=msname, fitsfile=fitsname, overwrite=False),
77 83 "exportuvfits succeeded but should have failed because "
78 84 + "overwrite=False"
79 85 )
80 86 # succeed because overwrite=True
81 87 res = exportuvfits(vis=msname, fitsfile=fitsname, overwrite=True)
82 88 if is_CASA6:
83 89 self.assertTrue(
84 90 res == None,
85 91 "exportuvfits failed but should have succeeded because "
86 92 + "overwrite=True"
87 93 )
88 94 else:
89 95 self.assertTrue(
90 96 res,
91 97 "exportuvfits failed but should have succeeded because "
92 98 + "overwrite=True"
93 99 )
94 -
95 100
96 101 def test_no_rest_freqs(self):
97 102 """CAS-11514: test exporting an MS with no rest frequencies in the SOURCE table"""
98 103 msname = "rest_freq_test.ms"
99 104 shutil.copytree(os.path.join(self.datapath, msname), msname)
100 105 fitsname = "no_rest_freqs.uvfits"
101 106 res = exportuvfits(vis=msname, fitsfile=fitsname)
102 107 if is_CASA6:
103 108 self.assertTrue(res == None, "Failed exportuvfits with no rest freqs")
104 109 else:
124 129 def test_no_source_table(self):
125 130 """CAS-11514: test exporting an MS with no rest frequencies in the SOURCE table"""
126 131 msname = "no_source_table.ms"
127 132 shutil.copytree(os.path.join(self.datapath, msname), msname)
128 133 fitsname = "no_source_table.uvfits"
129 134 res = exportuvfits(vis=msname, fitsfile=fitsname)
130 135 if is_CASA6:
131 136 self.assertTrue(res == None, "Failed exportuvfits with no SOURCE table")
132 137 else:
133 138 self.assertTrue(res, "Failed exportuvfits with no SOURCE table")
134 -
139 +
140 +
135 141 def suite():
136 - return [exportuvfits_test]
142 + return [exportuvfits_test]
143 +
137 144
138 145 if __name__ == '__main__':
139 146 unittest.main()

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

Add shortcut