Coverage for tests/test_Mq3cPixelization.py: 20%

71 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-14 01:58 -0800

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# 

22 

23import pickle 

24 

25try: 

26 import yaml 

27except ImportError: 

28 yaml = None 

29 

30import unittest 

31 

32from lsst.sphgeom import Angle, Circle, Mq3cPixelization, RangeSet, UnitVector3d 

33 

34 

35class Mq3cPixelizationTestCase(unittest.TestCase): 

36 def test_construction(self): 

37 with self.assertRaises(ValueError): 

38 Mq3cPixelization(-1) 

39 with self.assertRaises(ValueError): 

40 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1) 

41 m1 = Mq3cPixelization(0) 

42 self.assertEqual(m1.getLevel(), 0) 

43 m2 = Mq3cPixelization(1) 

44 m3 = Mq3cPixelization(m2) 

45 self.assertNotEqual(m1, m2) 

46 self.assertEqual(m2, m3) 

47 

48 def test_indexing(self): 

49 pixelization = Mq3cPixelization(1) 

50 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 53) 

51 

52 def test_level(self): 

53 self.assertEqual(Mq3cPixelization.level(0), -1) 

54 for level in range(Mq3cPixelization.MAX_LEVEL + 1): 

55 for root in range(8, 10): 

56 index = root * 4**level 

57 self.assertEqual(Mq3cPixelization.level(index), -1) 

58 for root in range(10, 16): 

59 index = root * 4**level 

60 self.assertEqual(Mq3cPixelization.level(index), level) 

61 

62 def test_envelope_and_interior(self): 

63 pixelization = Mq3cPixelization(1) 

64 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1)) 

65 rs = pixelization.envelope(c) 

66 self.assertTrue(rs == RangeSet(44)) 

67 rs = pixelization.envelope(c, 1) 

68 self.assertTrue(rs == RangeSet(44)) 

69 self.assertTrue(rs.isWithin(pixelization.universe())) 

70 rs = pixelization.interior(c) 

71 self.assertTrue(rs.empty()) 

72 

73 def test_index_to_string(self): 

74 strings = ["+X", "+Y", "+Z", "-X", "-Y", "-Z"] 

75 for i in range(6): 

76 s0 = strings[i] 

77 components = [0.0] * 3 

78 components[i % 3] = 1.0 if i < 3 else -1.0 

79 v = UnitVector3d(*components) 

80 f = Mq3cPixelization(0).index(v) 

81 self.assertEqual(Mq3cPixelization.asString(f), s0) 

82 self.assertEqual(Mq3cPixelization(0).toString(f), s0) 

83 for j in range(4): 

84 s1 = s0 + str(j) 

85 self.assertEqual(Mq3cPixelization.asString(f * 4 + j), s1) 

86 self.assertEqual(Mq3cPixelization(1).toString(f * 4 + j), s1) 

87 

88 def test_string(self): 

89 p = Mq3cPixelization(3) 

90 self.assertEqual(str(p), "Mq3cPixelization(3)") 

91 self.assertEqual(str(p), repr(p)) 

92 self.assertEqual(p, eval(repr(p), dict(Mq3cPixelization=Mq3cPixelization))) 

93 

94 def test_pickle(self): 

95 a = Mq3cPixelization(20) 

96 b = pickle.loads(pickle.dumps(a)) 

97 self.assertEqual(a, b) 

98 

99 @unittest.skipIf(not yaml, "YAML module can not be imported") 

100 def test_yaml(self): 

101 a = Mq3cPixelization(20) 

102 b = yaml.safe_load(yaml.dump(a)) 

103 self.assertEqual(a, b) 

104 

105 

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

107 unittest.main()