Coverage for tests/test_maskInfo.py: 16%

58 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-28 03:28 -0700

1# This file is part of cbp. 

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

26from lsst.cbp import MaskInfo 

27 

28 

29class MaskInfoTestCase(lsst.utils.tests.TestCase): 

30 def setUp(self): 

31 self.holePositions = ( 

32 (0, 0), 

33 (1, -2), 

34 (-3, 4), 

35 (5, 6), 

36 ) 

37 # A useful set of hole names that are not the default. 

38 self.holeNames = ["beam{}".format(i) for i in range(len(self.holePositions))] 

39 

40 def testBasics(self): 

41 name = "test mask" 

42 defaultHole = 2 

43 self.assertEqual(len(self.holeNames), len(self.holePositions)) 

44 mi = MaskInfo( 

45 name=name, 

46 defaultHole=defaultHole, 

47 holePositions=self.holePositions, 

48 holeNames=self.holeNames, 

49 ) 

50 self.assertEqual(mi.name, name) 

51 self.assertEqual(mi.numHoles, len(self.holePositions)) 

52 self.assertEqual(list(mi.holeNames), self.holeNames) 

53 self.assertEqual(mi.asHoleName(None), self.holeNames[defaultHole]) 

54 self.assertEqual(mi.getHolePos(None), lsst.geom.Point2D(*self.holePositions[defaultHole])) 

55 for i in range(-mi.numHoles, mi.numHoles): 

56 holeName = mi.asHoleName(i) 

57 desiredHoleName = self.holeNames[i] 

58 self.assertEqual(holeName, desiredHoleName) 

59 desiredHolePosition = lsst.geom.Point2D(*self.holePositions[i]) 

60 self.assertEqual(mi.getHolePos(holeName), desiredHolePosition) 

61 self.assertEqual(mi.getHolePos(i), desiredHolePosition) 

62 

63 with self.assertRaises(LookupError): 

64 mi.asHoleName("invalidName") 

65 with self.assertRaises(LookupError): 

66 mi.asHoleName(len(self.holePositions)) 

67 with self.assertRaises(LookupError): 

68 mi.asHoleName(-len(self.holePositions) - 1) 

69 

70 def testConstructorErrors(self): 

71 # defaultHole must not be None 

72 with self.assertRaises(ValueError): 

73 MaskInfo(name="test", defaultHole=None, holePositions=self.holePositions) 

74 with self.assertRaises(ValueError): 

75 MaskInfo(name="test", defaultHole=None, holePositions=self.holePositions, 

76 holeNames=self.holeNames) 

77 

78 # defaultHole must be a valid name or index, 

79 # but unlike None, this raises LookupError 

80 # so it has to be a separate test. 

81 for invalidHole in (len(self.holePositions), "bad"): 

82 with self.assertRaises(LookupError): 

83 MaskInfo(name="test", defaultHole=invalidHole, holePositions=self.holePositions) 

84 with self.assertRaises(LookupError): 

85 MaskInfo(name="test", defaultHole=invalidHole, holePositions=self.holePositions, 

86 holeNames=self.holeNames) 

87 

88 # The number of hole names must match the number of hole positions. 

89 holeNamesTooShort = self.holeNames[0: -1] 

90 with self.assertRaises(ValueError): 

91 MaskInfo(name="test", defaultHole=0, holePositions=self.holePositions, 

92 holeNames=holeNamesTooShort) 

93 

94 holeNamesTooLong = self.holeNames + ["extra"] 

95 with self.assertRaises(ValueError): 

96 MaskInfo(name="test", defaultHole=0, holePositions=self.holePositions, 

97 holeNames=holeNamesTooLong) 

98 

99 def testDefaultNames(self): 

100 mi = MaskInfo( 

101 name="test", 

102 defaultHole=1, 

103 holePositions=self.holePositions, 

104 ) 

105 self.assertEqual(mi.numHoles, len(self.holePositions)) 

106 self.assertEqual(list(mi.holeNames), [str(i) for i in range(len(self.holePositions))]) 

107 

108 

109class MemoryTester(lsst.utils.tests.MemoryTestCase): 

110 pass 

111 

112 

113def setup_module(module): 

114 lsst.utils.tests.init() 

115 

116 

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

118 lsst.utils.tests.init() 

119 unittest.main()