Coverage for tests/test_packers.py: 47%

34 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-03-28 09:48 +0000

1# This file is part of skymap. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

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

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21 

22import unittest 

23 

24import lsst.utils.tests 

25 

26try: 

27 from lsst.daf.butler import DimensionUniverse, DimensionGraph, DataCoordinate 

28 HAVE_DAF_BUTLER = True 

29except ImportError: 

30 HAVE_DAF_BUTLER = False 

31 

32from lsst.skymap.packers import SkyMapDimensionPacker 

33 

34 

35@unittest.skipUnless(HAVE_DAF_BUTLER, "daf_butler not setup") 

36class SkyMapDimensionPackerTestCase(lsst.utils.tests.TestCase): 

37 

38 def setUp(self): 

39 self.universe = DimensionUniverse() 

40 self.fixed = DataCoordinate.fromFullValues( 

41 DimensionGraph(universe=self.universe, names=["skymap"]), 

42 values=("unimportant",), 

43 ).expanded( 

44 records={ 

45 "skymap": self.universe["skymap"].RecordClass( 

46 name="unimportant", 

47 tract_max=5, 

48 patch_nx_max=3, 

49 patch_ny_max=3, 

50 ) 

51 } 

52 ) 

53 

54 def testWithoutFilter(self): 

55 dimensions = DimensionGraph(universe=self.universe, names=["tract", "patch"]) 

56 dataId = DataCoordinate.standardize( 

57 skymap=self.fixed["skymap"], 

58 tract=2, 

59 patch=6, 

60 universe=self.universe 

61 ) 

62 packer = SkyMapDimensionPacker(self.fixed, dimensions) 

63 packedId = packer.pack(dataId) 

64 self.assertLessEqual(packedId.bit_length(), packer.maxBits) 

65 self.assertEqual(packer.unpack(packedId), dataId) 

66 

67 def testWithFilter(self): 

68 dimensions = DimensionGraph(universe=self.universe, names=["tract", "patch", "band"]) 

69 dataId = DataCoordinate.standardize( 

70 skymap=self.fixed["skymap"], 

71 tract=2, 

72 patch=6, 

73 band="g", 

74 universe=self.universe 

75 ) 

76 packer = SkyMapDimensionPacker(self.fixed, dimensions) 

77 packedId = packer.pack(dataId) 

78 self.assertLessEqual(packedId.bit_length(), packer.maxBits) 

79 self.assertEqual(packer.unpack(packedId), dataId) 

80 

81 

82class MemoryTester(lsst.utils.tests.MemoryTestCase): 

83 pass 

84 

85 

86def setup_module(module): 

87 lsst.utils.tests.init() 

88 

89 

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

91 lsst.utils.tests.init() 

92 unittest.main()