Coverage for tests/test_HtmPixelization.py: 24%
67 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-19 11:56 +0000
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-19 11:56 +0000
1#
2# LSST Data Management System
3# See COPYRIGHT file at the top of the source tree.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <https://www.lsstcorp.org/LegalNotices/>.
21#
23import pickle
25try:
26 import yaml
27except ImportError:
28 yaml = None
30import unittest
32from lsst.sphgeom import Angle, Circle, ConvexPolygon, HtmPixelization, RangeSet, UnitVector3d
35class HtmPixelizationTestCase(unittest.TestCase):
36 def test_construction(self):
37 with self.assertRaises(ValueError):
38 HtmPixelization(-1)
39 with self.assertRaises(ValueError):
40 HtmPixelization(HtmPixelization.MAX_LEVEL + 1)
41 h1 = HtmPixelization(0)
42 self.assertEqual(h1.getLevel(), 0)
43 h2 = HtmPixelization(1)
44 h3 = HtmPixelization(h2)
45 self.assertNotEqual(h1, h2)
46 self.assertEqual(h2, h3)
48 def test_indexing(self):
49 h = HtmPixelization(1)
50 self.assertEqual(h.index(UnitVector3d(1, 1, 1)), 63)
52 def test_pixel(self):
53 h = HtmPixelization(1)
54 self.assertIsInstance(h.pixel(10), ConvexPolygon)
56 def test_level(self):
57 for index in (0, 16 * 4**HtmPixelization.MAX_LEVEL):
58 self.assertEqual(HtmPixelization.level(index), -1)
59 for level in range(HtmPixelization.MAX_LEVEL + 1):
60 for root in range(8, 16):
61 self.assertEqual(HtmPixelization.level(root * 4**level), level)
63 def test_envelope_and_interior(self):
64 pixelization = HtmPixelization(3)
65 c = Circle(UnitVector3d(1, 1, 1), Angle.fromDegrees(0.1))
66 rs = pixelization.envelope(c)
67 self.assertTrue(rs == RangeSet(0x3FF))
68 rs = pixelization.envelope(c, 1)
69 self.assertTrue(rs == RangeSet(0x3FF))
70 self.assertTrue(rs.isWithin(pixelization.universe()))
71 rs = pixelization.interior(c)
72 self.assertTrue(rs.empty())
74 def test_index_to_string(self):
75 strings = ["S0", "S1", "S2", "S3", "N0", "N1", "N2", "N3"]
76 for i in range(8, 16):
77 s0 = strings[i - 8]
78 self.assertEqual(HtmPixelization.asString(i), s0)
79 self.assertEqual(HtmPixelization(0).toString(i), s0)
80 for j in range(4):
81 s1 = s0 + str(j)
82 self.assertEqual(HtmPixelization.asString(i * 4 + j), s1)
83 self.assertEqual(HtmPixelization(1).asString(i * 4 + j), s1)
85 def test_string(self):
86 p = HtmPixelization(3)
87 self.assertEqual(str(p), "HtmPixelization(3)")
88 self.assertEqual(str(p), repr(p))
89 self.assertEqual(p, eval(repr(p), dict(HtmPixelization=HtmPixelization)))
91 def test_pickle(self):
92 a = HtmPixelization(20)
93 b = pickle.loads(pickle.dumps(a))
94 self.assertEqual(a, b)
96 @unittest.skipIf(not yaml, "YAML module can not be imported")
97 def test_yaml(self):
98 a = HtmPixelization(20)
99 b = yaml.safe_load(yaml.dump(a))
100 self.assertEqual(a, b)
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 unittest.main()