Coverage for tests/test_pickles.py: 52%
81 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-06-06 09:41 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-06-06 09:41 +0000
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#
22"""
23Tests for pickles of some afw types
24"""
26import unittest
27import pickle
29import lsst.utils.tests
30import lsst.geom
33class PickleBase:
34 """A test case for pickles"""
36 def setUp(self):
37 raise NotImplementedError(
38 "Need to inherit and create the 'data' element.")
40 def tearDown(self):
41 del self.data
43 def assertPickled(self, new):
44 """Assert that the pickled data is the same as the original
46 Subclasses should override this method if the particular data
47 doesn't support the == operator.
48 """
49 self.assertEqual(new, self.data)
51 def testPickle(self):
52 """Test round-trip pickle"""
53 pickled = pickle.dumps(self.data)
54 newData = pickle.loads(pickled)
55 self.assertPickled(newData)
58class AngleTestCase(PickleBase, unittest.TestCase):
60 def setUp(self):
61 self.data = 1.0*lsst.geom.degrees
64class Point2DTestCase(PickleBase, unittest.TestCase):
66 def setUp(self):
67 x, y = 1.0, 1.0
68 self.data = lsst.geom.Point2D(x, y)
71class Point2ITestCase(PickleBase, unittest.TestCase):
73 def setUp(self):
74 x, y = 1, 1
75 self.data = lsst.geom.Point2I(x, y)
78class Point3DTestCase(PickleBase, unittest.TestCase):
80 def setUp(self):
81 x, y, z = 1.0, 1.0, 1.0
82 self.data = lsst.geom.Point3D(x, y, z)
85class Point3ITestCase(PickleBase, unittest.TestCase):
87 def setUp(self):
88 x, y, z = 1, 1, 1
89 self.data = lsst.geom.Point3I(x, y, z)
92class Extent2DTestCase(PickleBase, unittest.TestCase):
94 def setUp(self):
95 x, y = 1.0, 1.0
96 self.data = lsst.geom.Extent2D(x, y)
99class Extent3DTestCase(PickleBase, unittest.TestCase):
101 def setUp(self):
102 x, y, z = 1, 1, 1
103 self.data = lsst.geom.Extent3D(x, y, z)
106class Extent2ITestCase(PickleBase, unittest.TestCase):
108 def setUp(self):
109 x, y = 1, 1
110 self.data = lsst.geom.Extent2I(x, y)
113class Extent3ITestCase(PickleBase, unittest.TestCase):
115 def setUp(self):
116 x, y, z = 1, 1, 1
117 self.data = lsst.geom.Extent3I(x, y, z)
120class Box2DTestCase(PickleBase, unittest.TestCase):
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)
127class Box2ITestCase(PickleBase, unittest.TestCase):
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)
134class AffineTransformTestCase(PickleBase, unittest.TestCase):
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)
143 def assertPickled(self, new):
144 self.assertListEqual(new.getMatrix().flatten().tolist(),
145 self.data.getMatrix().flatten().tolist())
148class LinearTransformTestCase(PickleBase, unittest.TestCase):
150 def setUp(self):
151 scale = 2.0
152 self.data = lsst.geom.LinearTransform().makeScaling(scale)
154 def assertPickled(self, new):
155 self.assertListEqual(new.getMatrix().flatten().tolist(),
156 self.data.getMatrix().flatten().tolist())
159class TestMemory(lsst.utils.tests.MemoryTestCase):
160 pass
163def setup_module(module):
164 lsst.utils.tests.init()
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()