Coverage for tests/test_taskConfigs.py : 14%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of <REPLACE WHEN RENAMED>.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Unit tests for the metrics measurement system: configs.
23"""
25import unittest
27from lsst.faro.measurement import (AMxTask, ADxTask, AFxTask,
28 PA1Task, PA2Task, PF1Task,
29 TExTask, AB1Task, WPerpTask)
32class ConfigTest(unittest.TestCase):
34 def check_config(self, task, expected, default, check_fields):
35 """This checks both that there are attributes on the task
36 that match the expected configuration as well as that the
37 configuration is different than the default config.
38 """
39 for field in check_fields:
40 self.assertEqual(getattr(task.config, field), getattr(expected, field))
41 self.assertNotEqual(getattr(task.config, field), getattr(default, field))
43 # AMxTask, ADxTask, and AFxTask share a config so we are really only testing
44 # how the tasks apply the config
45 def test_amx_config(self):
46 """Test application of config for AMx task"""
47 default = AMxTask.ConfigClass()
48 expected = AMxTask.ConfigClass()
49 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
50 'threshAD', 'threshAF', 'bins']
51 expected.annulus_r = 11.7
52 expected.width = 3.33
53 expected.bright_mag_cut = 20.0
54 expected.faint_mag_cut = 23.8
55 expected.threshAD = 19.63
56 expected.threshAF = 11.55
57 expected.bins = [0.5, 1.6, 3.1, 2.8]
58 task = AMxTask(config=expected)
59 self.check_config(task, expected, default, field_list)
61 def test_adx_config(self):
62 """Test application of config for ADx task"""
63 default = ADxTask.ConfigClass()
64 expected = ADxTask.ConfigClass()
65 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
66 'threshAD', 'threshAF', 'bins']
67 expected.annulus_r = 11.7
68 expected.width = 3.33
69 expected.bright_mag_cut = 20.0
70 expected.faint_mag_cut = 23.8
71 expected.threshAD = 19.63
72 expected.threshAF = 11.55
73 expected.bins = [0.5, 1.6, 3.1, 2.8]
74 task = ADxTask(config=expected)
75 self.check_config(task, expected, default, field_list)
77 def test_afx_config(self):
78 """Test application of config for AFx task"""
79 default = AFxTask.ConfigClass()
80 expected = AFxTask.ConfigClass()
81 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
82 'threshAD', 'threshAF', 'bins']
83 expected.annulus_r = 11.7
84 expected.width = 3.33
85 expected.bright_mag_cut = 20.0
86 expected.faint_mag_cut = 23.8
87 expected.threshAD = 19.63
88 expected.threshAF = 11.55
89 expected.bins = [0.5, 1.6, 3.1, 2.8]
90 task = AFxTask(config=expected)
91 self.check_config(task, expected, default, field_list)
93 def test_pa1_config(self):
94 """Test application of config for PA1 task"""
95 default = PA1Task.ConfigClass()
96 expected = PA1Task.ConfigClass()
97 field_list = ['brightSnrMin', 'brightSnrMax']
98 expected.brightSnrMin = 100.0
99 expected.brightSnrMax = 31415.9
100 task = PA1Task(config=expected)
101 # Some config attriutes are also used to populate task attriubtes
102 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin)
103 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax)
104 self.check_config(task, expected, default, field_list)
106 def test_pa2_config(self):
107 """Test application of config for PA2 task"""
108 default = PA2Task.ConfigClass()
109 expected = PA2Task.ConfigClass()
110 field_list = ['brightSnrMin', 'brightSnrMax']
111 expected.brightSnrMin = 100.0
112 expected.brightSnrMax = 31415.9
113 task = PA2Task(config=expected)
114 # Some config attriutes are also used to populate task attriubtes
115 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin)
116 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax)
117 self.check_config(task, expected, default, field_list)
119 def test_pf1_config(self):
120 """Test application of config for PF1 task"""
121 default = PF1Task.ConfigClass()
122 expected = PF1Task.ConfigClass()
123 field_list = ['brightSnrMin', 'brightSnrMax', 'threshPA2', 'threshPF1']
124 expected.brightSnrMin = 100.0
125 expected.brightSnrMax = 31415.9
126 expected.threshPA2 = 17.47
127 expected.threshPF1 = 9.892
128 task = PF1Task(config=expected)
129 # Some config attriutes are also used to populate task attriubtes
130 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin)
131 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax)
132 self.assertEqual(task.config.threshPA2, expected.threshPA2)
133 self.assertEqual(task.config.threshPF1, expected.threshPF1)
134 self.check_config(task, expected, default, field_list)
136 def test_tex_config(self):
137 """Test application of config for TEx task"""
138 default = TExTask.ConfigClass()
139 expected = TExTask.ConfigClass()
140 field_list = ['annulus_r', 'comparison_operator']
141 expected.annulus_r = 42.0
142 expected.comparison_operator = 'bigger'
143 task = TExTask(config=expected)
144 self.check_config(task, expected, default, field_list)
146 def test_ab1_config(self):
147 """Test application of config for AB1 task"""
148 default = AB1Task.ConfigClass()
149 expected = AB1Task.ConfigClass()
150 field_list = ['bright_mag_cut', 'faint_mag_cut', 'ref_filter']
151 expected.bright_mag_cut = 25.3
152 expected.faint_mag_cut = 38.2
153 expected.ref_filter = 'p'
154 task = AB1Task(config=expected)
155 self.check_config(task, expected, default, field_list)
157 def test_wperp_config(self):
158 """Test application of config for wPerp task"""
159 default = WPerpTask.ConfigClass()
160 expected = WPerpTask.ConfigClass()
161 field_list = ['bright_rmag_cut', 'faint_rmag_cut']
162 expected.bright_rmag_cut = 25.3
163 expected.faint_rmag_cut = 38.2
164 task = WPerpTask(config=expected)
165 self.check_config(task, expected, default, field_list)
168if __name__ == "__main__": 168 ↛ 169line 168 didn't jump to line 169, because the condition on line 168 was never true
169 unittest.main()