Coverage for tests/test_HtmPixelization.py : 21%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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
24import yaml
25import unittest
27from lsst.sphgeom import Angle, Circle, HtmPixelization, RangeSet, UnitVector3d, ConvexPolygon
30class HtmPixelizationTestCase(unittest.TestCase):
32 def test_construction(self):
33 with self.assertRaises(ValueError):
34 HtmPixelization(-1)
35 with self.assertRaises(ValueError):
36 HtmPixelization(HtmPixelization.MAX_LEVEL + 1)
37 h1 = HtmPixelization(0)
38 self.assertEqual(h1.getLevel(), 0)
39 h2 = HtmPixelization(1)
40 h3 = HtmPixelization(h2)
41 self.assertNotEqual(h1, h2)
42 self.assertEqual(h2, h3)
44 def test_indexing(self):
45 h = HtmPixelization(1)
46 self.assertEqual(h.index(UnitVector3d(1, 1, 1)), 63)
48 def test_pixel(self):
49 h = HtmPixelization(1)
50 self.assertIsInstance(h.pixel(10), ConvexPolygon)
52 def test_level(self):
53 for index in (0, 16 * 4**HtmPixelization.MAX_LEVEL):
54 self.assertEqual(HtmPixelization.level(index), -1)
55 for level in range(HtmPixelization.MAX_LEVEL + 1):
56 for root in range(8, 16):
57 self.assertEqual(HtmPixelization.level(root * 4**level), level)
59 def test_envelope_and_interior(self):
60 pixelization = HtmPixelization(3)
61 c = Circle(UnitVector3d(1, 1, 1), Angle.fromDegrees(0.1))
62 rs = pixelization.envelope(c)
63 self.assertTrue(rs == RangeSet(0x3ff))
64 rs = pixelization.envelope(c, 1)
65 self.assertTrue(rs == RangeSet(0x3ff))
66 self.assertTrue(rs.isWithin(pixelization.universe()))
67 rs = pixelization.interior(c)
68 self.assertTrue(rs.empty())
70 def test_index_to_string(self):
71 strings = ['S0', 'S1', 'S2', 'S3', 'N0', 'N1', 'N2', 'N3']
72 for i in range(8, 16):
73 s0 = strings[i - 8]
74 self.assertEqual(HtmPixelization.asString(i), s0)
75 self.assertEqual(HtmPixelization(0).toString(i), s0)
76 for j in range(4):
77 s1 = s0 + str(j)
78 self.assertEqual(HtmPixelization.asString(i*4 + j), s1)
79 self.assertEqual(HtmPixelization(1).asString(i*4 + j), s1)
81 def test_string(self):
82 p = HtmPixelization(3)
83 self.assertEqual(str(p), 'HtmPixelization(3)')
84 self.assertEqual(str(p), repr(p))
85 self.assertEqual(
86 p, eval(repr(p), dict(HtmPixelization=HtmPixelization)))
88 def test_pickle(self):
89 a = HtmPixelization(20)
90 b = pickle.loads(pickle.dumps(a))
91 self.assertEqual(a, b)
93 def test_yaml(self):
94 a = HtmPixelization(20)
95 b = yaml.safe_load(yaml.dump(a))
96 self.assertEqual(a, b)
99if __name__ == '__main__': 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true
100 unittest.main()