Coverage for tests/test_pickles.py: 52%

81 statements  

« prev     ^ index     » next       coverage.py v7.2.3, created at 2023-04-26 06:14 -0700

1# 

2# Developed for the LSST Data Management System. 

3# This product includes software developed by the LSST Project 

4# (https://www.lsst.org). 

5# See the COPYRIGHT file at the top-level directory of this distribution 

6# for details of code ownership. 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the GNU General Public License 

19# along with this program. If not, see <https://www.gnu.org/licenses/>. 

20# 

21 

22""" 

23Tests for pickles of some afw types 

24""" 

25 

26import unittest 

27import pickle 

28 

29import lsst.utils.tests 

30import lsst.geom 

31 

32 

33class PickleBase: 

34 """A test case for pickles""" 

35 

36 def setUp(self): 

37 raise NotImplementedError( 

38 "Need to inherit and create the 'data' element.") 

39 

40 def tearDown(self): 

41 del self.data 

42 

43 def assertPickled(self, new): 

44 """Assert that the pickled data is the same as the original 

45 

46 Subclasses should override this method if the particular data 

47 doesn't support the == operator. 

48 """ 

49 self.assertEqual(new, self.data) 

50 

51 def testPickle(self): 

52 """Test round-trip pickle""" 

53 pickled = pickle.dumps(self.data) 

54 newData = pickle.loads(pickled) 

55 self.assertPickled(newData) 

56 

57 

58class AngleTestCase(PickleBase, unittest.TestCase): 

59 

60 def setUp(self): 

61 self.data = 1.0*lsst.geom.degrees 

62 

63 

64class Point2DTestCase(PickleBase, unittest.TestCase): 

65 

66 def setUp(self): 

67 x, y = 1.0, 1.0 

68 self.data = lsst.geom.Point2D(x, y) 

69 

70 

71class Point2ITestCase(PickleBase, unittest.TestCase): 

72 

73 def setUp(self): 

74 x, y = 1, 1 

75 self.data = lsst.geom.Point2I(x, y) 

76 

77 

78class Point3DTestCase(PickleBase, unittest.TestCase): 

79 

80 def setUp(self): 

81 x, y, z = 1.0, 1.0, 1.0 

82 self.data = lsst.geom.Point3D(x, y, z) 

83 

84 

85class Point3ITestCase(PickleBase, unittest.TestCase): 

86 

87 def setUp(self): 

88 x, y, z = 1, 1, 1 

89 self.data = lsst.geom.Point3I(x, y, z) 

90 

91 

92class Extent2DTestCase(PickleBase, unittest.TestCase): 

93 

94 def setUp(self): 

95 x, y = 1.0, 1.0 

96 self.data = lsst.geom.Extent2D(x, y) 

97 

98 

99class Extent3DTestCase(PickleBase, unittest.TestCase): 

100 

101 def setUp(self): 

102 x, y, z = 1, 1, 1 

103 self.data = lsst.geom.Extent3D(x, y, z) 

104 

105 

106class Extent2ITestCase(PickleBase, unittest.TestCase): 

107 

108 def setUp(self): 

109 x, y = 1, 1 

110 self.data = lsst.geom.Extent2I(x, y) 

111 

112 

113class Extent3ITestCase(PickleBase, unittest.TestCase): 

114 

115 def setUp(self): 

116 x, y, z = 1, 1, 1 

117 self.data = lsst.geom.Extent3I(x, y, z) 

118 

119 

120class Box2DTestCase(PickleBase, unittest.TestCase): 

121 

122 def setUp(self): 

123 p, e = lsst.geom.Point2D(1.0, 1.0), lsst.geom.Extent2D(0.5, 0.5) 

124 self.data = lsst.geom.Box2D(p, e) 

125 

126 

127class Box2ITestCase(PickleBase, unittest.TestCase): 

128 

129 def setUp(self): 

130 p, e = lsst.geom.Point2I(1, 2), lsst.geom.Extent2I(1, 1) 

131 self.data = lsst.geom.Box2I(p, e) 

132 

133 

134class AffineTransformTestCase(PickleBase, unittest.TestCase): 

135 

136 def setUp(self): 

137 scale = 2.2 

138 linear = lsst.geom.LinearTransform().makeScaling(scale) 

139 dx, dy = 1.1, 3.3 

140 trans = lsst.geom.Extent2D(dx, dy) 

141 self.data = lsst.geom.AffineTransform(linear, trans) 

142 

143 def assertPickled(self, new): 

144 self.assertListEqual(new.getMatrix().flatten().tolist(), 

145 self.data.getMatrix().flatten().tolist()) 

146 

147 

148class LinearTransformTestCase(PickleBase, unittest.TestCase): 

149 

150 def setUp(self): 

151 scale = 2.0 

152 self.data = lsst.geom.LinearTransform().makeScaling(scale) 

153 

154 def assertPickled(self, new): 

155 self.assertListEqual(new.getMatrix().flatten().tolist(), 

156 self.data.getMatrix().flatten().tolist()) 

157 

158 

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

160 pass 

161 

162 

163def setup_module(module): 

164 lsst.utils.tests.init() 

165 

166 

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

168 lsst.utils.tests.init() 

169 unittest.main()