Coverage for tests/test_butler.py: 33%
52 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-28 03:00 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-28 03:00 -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#
23import os
24import unittest
25import warnings
27import lsst.daf.persistence as dafPersist
28import lsst.utils.tests
29from lsst.ip.isr import Linearizer, LinearizeLookupTable
30from lsst.utils import getPackageDir
33class ButlerTestCase(unittest.TestCase):
34 """Testing butler policy setup"""
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)
44 self.repoPath = os.path.join(datadir, "rawData")
45 self.butler = dafPersist.Butler(root=self.repoPath)
47 def tearDown(self):
48 del self.butler
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)
56 subset = self.butler.subset("raw", level="sensor", visit=229388)
57 print("ButlerSubset.cache: %s" % subset.cache)
58 self.assertEqual(len(subset), 2)
60 subset = self.butler.subset("raw", level="visit", visit=229388)
61 print("ButlerSubset.cache: %s" % subset.cache)
62 self.assertEqual(len(subset), 1)
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")
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)
88class MemoryTester(lsst.utils.tests.MemoryTestCase):
89 pass
92def setup_module(module):
93 lsst.utils.tests.init()
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()