Coverage for tests/test_ApCorrNameSet.py: 35%

47 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-04 03:06 -0700

1# This file is part of meas_base. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import unittest 

23 

24import lsst.utils.tests 

25import lsst.meas.base 

26 

27 

28class MinimalistTestPlugin(lsst.meas.base.SingleFramePlugin): 

29 """Minimal plugin implementation. 

30 

31 Notes 

32 ----- 

33 This class is used below to test registration. It is set up as the 

34 minimal class that still has a valid implementation. Whilst these 

35 methods are not needed in this test file, the class registered here 

36 might appear in other tests that scan the registry. 

37 """ 

38 @classmethod 

39 def getExecutionOrder(cls): 

40 return cls.CENTROID_ORDER 

41 

42 def fail(self, measRecord, error=None): 

43 pass 

44 

45 

46class ApCorrNameTestCase(lsst.utils.tests.TestCase): 

47 

48 def testDefaultNames(self): 

49 apCorrSet = lsst.meas.base.getApCorrNameSet() 

50 self.assertIn("base_PsfFlux", apCorrSet) 

51 self.assertIn("base_GaussianFlux", apCorrSet) 

52 

53 def testAdd(self): 

54 nameSet0 = lsst.meas.base.getApCorrNameSet() 

55 

56 lsst.meas.base.addApCorrName("test_NewName") 

57 nameSet1 = lsst.meas.base.getApCorrNameSet() 

58 self.assertIn("test_NewName", nameSet1) 

59 self.assertEqual(len(nameSet1 - nameSet0), 1) 

60 

61 # adding a name twice is silently ignored 

62 lsst.meas.base.addApCorrName("test_NewName") 

63 nameSet2 = lsst.meas.base.getApCorrNameSet() 

64 self.assertIn("test_NewName", nameSet2) 

65 self.assertEqual(len(nameSet2 - nameSet1), 0) 

66 

67 def testCopy(self): 

68 """Make sure `getApCorrNameSet` returns a copy. 

69 """ 

70 nameSet0 = lsst.meas.base.getApCorrNameSet() 

71 nameSet0.add("test_LocalName") 

72 nameSet1 = lsst.meas.base.getApCorrNameSet() 

73 self.assertNotIn("test_LocalName", nameSet1) 

74 self.assertEqual(len(nameSet0 - nameSet1), 1) 

75 

76 def testRegisterDecorator(self): 

77 """Test the ``shouldApCorr`` argument to plugin registration. 

78 """ 

79 @lsst.meas.base.register("test_ApCorrPlugin", shouldApCorr=True) 

80 class ApCorrPlugin(MinimalistTestPlugin): 

81 pass 

82 

83 @lsst.meas.base.register("test_NonApCorrPlugin") 

84 class NonApCorrPlugin(MinimalistTestPlugin): 

85 pass 

86 

87 apCorrSet = lsst.meas.base.getApCorrNameSet() 

88 self.assertIn("test_ApCorrPlugin", apCorrSet) 

89 self.assertNotIn("test_NonApCorrPlugin", apCorrSet) 

90 

91 

92class TestMemory(lsst.utils.tests.MemoryTestCase): 

93 pass 

94 

95 

96def setup_module(module): 

97 lsst.utils.tests.init() 

98 

99 

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

101 lsst.utils.tests.init() 

102 unittest.main()