1 - | |
2 - | |
3 - | |
4 - | |
5 - | |
6 - | |
7 - | from __future__ import absolute_import |
8 - | import os |
9 - | import sys |
10 - | |
11 - | from casatasks.private.casa_transition import is_CASA6 |
12 - | if is_CASA6: |
13 - | from casatools import ctsys |
14 - | from casatasks import asdmsummary, casalog |
15 - | |
16 - | else: |
17 - | from __main__ import default |
18 - | from tasks import asdmsummary |
19 - | from taskinit import casalog |
20 - | |
21 - | import unittest |
22 - | |
23 - | def logfileLen(): |
24 - | |
25 - | result = 0 |
26 - | logfile = casalog.logfile() |
27 - | if os.path.isfile(logfile): |
28 - | with open(logfile) as f: |
29 - | for result, l in enumerate(f,1): |
30 - | pass |
31 - | return result |
32 - | |
33 - | def taskLogRange(startat): |
34 - | |
35 - | |
36 - | |
37 - | |
38 - | |
39 - | |
40 - | firstLine = -1 |
41 - | lastLine = -1 |
42 - | logfile = casalog.logfile() |
43 - | if os.path.isfile(logfile): |
44 - | with open(logfile) as f: |
45 - | |
46 - | for lineNum, l in enumerate(f,1): |
47 - | |
48 - | if lineNum >= startat: |
49 - | if firstLine < 0: |
50 - | if ((l.find('Begin Task') >= 0) and (l.find('asdmsummary')>=0)): |
51 - | firstLine = lineNum |
52 - | else: |
53 - | if ((l.find('End Task') >= 0) and (l.find('asdmsummary')>=0)): |
54 - | lastLine = lineNum |
55 - | break |
56 - | return (firstLine,lastLine) |
57 - | |
58 - | class asdmsummary_test(unittest.TestCase): |
59 - | |
60 - | |
61 - | |
62 - | |
63 - | |
64 - | |
65 - | dataPath = "" |
66 - | extraLines = 0 |
67 - | if is_CASA6: |
68 - | dataPath = ctsys.resolve('unittest/asdmsummary/') |
69 - | else: |
70 - | dataPath = os.path.join(os.environ.get('CASAPATH').split()[0],'/casatestdata/unittest/asdmsummary/') |
71 - | extraLines = 8 |
72 - | |
73 - | def doASDMSummary(self, asdmpath, expectedLogLines): |
74 - | |
75 - | logLength = logfileLen() |
76 - | asdmsummary(os.path.join(self.dataPath,asdmpath)) |
77 - | (firstLine,lastLine) = taskLogRange(logLength) |
78 - | newLines = 0 |
79 - | if (firstLine >= 0) and (lastLine >= 0): |
80 - | newLines = lastLine-firstLine+1 |
81 - | |
82 - | self.assertTrue(False) |
83 - | |
84 - | def setUp(self): |
85 - | if is_CASA6: |
86 - | pass |
87 - | else: |
88 - | default(asdmsummary) |
89 - | |
90 - | def tearDown(self): |
91 - | pass |
92 - | |
93 - | def test_alma_asdm(self): |
94 - | ''' ALMA M51 data''' |
95 - | |
96 - | nlines = 170 |
97 - | self.doASDMSummary('uid___X5f_X18951_X1', nlines) |
98 - | |
99 - | def test_vla_asdm(self): |
100 - | '''VLA data''' |
101 - | |
102 - | nlines = 250 |
103 - | self.doASDMSummary('X_osro_013.55979.93803716435',nlines) |
104 - | |
105 - | def test_aca_asdm(self): |
106 - | '''ACA with mixed pol/channelisation''' |
107 - | |
108 - | nlines = 2517 |
109 - | self.doASDMSummary('uid___A002_X72bc38_X000',nlines) |
110 - | |
111 - | def test_12m_asdm(self): |
112 - | ''' 12m with mixedl pol/channelisation''' |
113 - | |
114 - | nlines = 1021 |
115 - | self.doASDMSummary('uid___A002_X71e4ae_X317_short',nlines) |
116 - | |
117 - | def suite(): |
118 - | return [asdmsummary_test] |
119 - | |
120 - | if is_CASA6: |
121 - | if __name__ == '__main__': |
122 - | unittest.main() |