Coverage for tests/test_butler.py: 29%

52 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-02 00:21 -0700

1# 

2# LSST Data Management System 

3# Copyright 2016 LSST Corporation. 

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 <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23import os 

24import unittest 

25import warnings 

26 

27import lsst.daf.persistence as dafPersist 

28import lsst.utils.tests 

29from lsst.ip.isr import Linearizer, LinearizeLookupTable 

30from lsst.utils import getPackageDir 

31 

32 

33class ButlerTestCase(unittest.TestCase): 

34 """Testing butler policy setup""" 

35 

36 def setUp(self): 

37 try: 

38 datadir = getPackageDir("testdata_decam") 

39 except LookupError: 

40 message = "testdata_decam not setup. Skipping." 

41 warnings.warn(message) 

42 raise unittest.SkipTest(message) 

43 

44 self.repoPath = os.path.join(datadir, "rawData") 

45 self.butler = dafPersist.Butler(root=self.repoPath) 

46 

47 def tearDown(self): 

48 del self.butler 

49 

50 def testButlerSubsetLevel(self): 

51 """Test if subset is gathered correctly for the specified level""" 

52 subset = self.butler.subset("raw", level="sensor", visit=229388, ccdnum=1) 

53 print("ButlerSubset.cache: %s" % subset.cache) 

54 self.assertEqual(len(subset), 1) 

55 

56 subset = self.butler.subset("raw", level="sensor", visit=229388) 

57 print("ButlerSubset.cache: %s" % subset.cache) 

58 self.assertEqual(len(subset), 2) 

59 

60 subset = self.butler.subset("raw", level="visit", visit=229388) 

61 print("ButlerSubset.cache: %s" % subset.cache) 

62 self.assertEqual(len(subset), 1) 

63 

64 def testGetCamera(self): 

65 """Test that we can get a camera""" 

66 camera = self.butler.get("camera") 

67 self.assertEqual(len(camera), 62) 

68 self.assertEqual(camera[1].getName(), "S29") 

69 self.assertEqual(camera[62].getName(), "N31") 

70 

71 def testGetLinearizer(self): 

72 """Test that we can get a linearizer""" 

73 camera = self.butler.get("camera") 

74 for ccdnum in (1, 62): 

75 detector = camera[ccdnum] 

76 linearizer = Linearizer(table=self.butler.get("linearizer", 

77 dataId=dict(ccdnum=ccdnum), 

78 immediate=True), 

79 detector=detector) 

80 for amp in detector: 

81 self.assertEqual(linearizer.linearityType[amp.getName()], LinearizeLookupTable.LinearityType) 

82 linearizer.validate(detector=detector) 

83 for badccdnum in (0, 63): 

84 with self.assertRaises(Exception): 

85 self.butler.get("linearizer", dataId=dict(ccdnum=badccdnum), immediate=True) 

86 

87 

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

89 pass 

90 

91 

92def setup_module(module): 

93 lsst.utils.tests.init() 

94 

95 

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

97 lsst.utils.tests.init() 

98 unittest.main()