Hide keyboard shortcuts

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/>. 

21 

22"""Unit tests for the metrics measurement system: configs. 

23""" 

24 

25import unittest 

26 

27from lsst.faro.measurement import (AMxTask, ADxTask, AFxTask, 

28 PA1Task, PF1Task, 

29 TExTask, AB1Task, WPerpTask) 

30 

31 

32class ConfigTest(unittest.TestCase): 

33 

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)) 

42 

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) 

60 

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) 

76 

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) 

92 

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) 

105 

106 def test_pf1_config(self): 

107 """Test application of config for PF1 task""" 

108 default = PF1Task.ConfigClass() 

109 expected = PF1Task.ConfigClass() 

110 field_list = ['brightSnrMin', 'brightSnrMax', 'threshPA2'] 

111 expected.brightSnrMin = 100.0 

112 expected.brightSnrMax = 31415.9 

113 expected.threshPA2 = 17.47 

114 task = PF1Task(config=expected) 

115 # Some config attriutes are also used to populate task attriubtes 

116 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin) 

117 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax) 

118 self.assertEqual(task.config.threshPA2, expected.threshPA2) 

119 self.check_config(task, expected, default, field_list) 

120 

121 def test_tex_config(self): 

122 """Test application of config for TEx task""" 

123 default = TExTask.ConfigClass() 

124 expected = TExTask.ConfigClass() 

125 field_list = ['annulus_r', 'comparison_operator'] 

126 expected.annulus_r = 42.0 

127 expected.comparison_operator = 'bigger' 

128 task = TExTask(config=expected) 

129 self.check_config(task, expected, default, field_list) 

130 

131 def test_ab1_config(self): 

132 """Test application of config for AB1 task""" 

133 default = AB1Task.ConfigClass() 

134 expected = AB1Task.ConfigClass() 

135 field_list = ['bright_mag_cut', 'faint_mag_cut', 'ref_filter'] 

136 expected.bright_mag_cut = 25.3 

137 expected.faint_mag_cut = 38.2 

138 expected.ref_filter = 'p' 

139 task = AB1Task(config=expected) 

140 self.check_config(task, expected, default, field_list) 

141 

142 def test_wperp_config(self): 

143 """Test application of config for wPerp task""" 

144 default = WPerpTask.ConfigClass() 

145 expected = WPerpTask.ConfigClass() 

146 field_list = ['bright_rmag_cut', 'faint_rmag_cut'] 

147 expected.bright_rmag_cut = 25.3 

148 expected.faint_rmag_cut = 38.2 

149 task = WPerpTask(config=expected) 

150 self.check_config(task, expected, default, field_list) 

151 

152 

153if __name__ == "__main__": 153 ↛ 154line 153 didn't jump to line 154, because the condition on line 153 was never true

154 unittest.main()