Coverage for python/lsst/obs/lsst/testHelper.py: 59%
39 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-04 03:10 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-04 03:10 -0800
1# This file is part of obs_lsst.
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#
23"""Test support classes for obs_lsst"""
24__all__ = ("ObsLsstButlerTests", "ObsLsstObsBaseOverrides")
26import os.path
27import unittest
28from abc import abstractmethod
30import lsst.utils.tests
31import lsst.obs.base.tests
32import lsst.daf.butler
33from lsst.utils import getPackageDir
35# Define the data location relative to this package
36DATAROOT = os.path.join(getPackageDir("obs_lsst"), "data", "input")
39class ObsLsstButlerTests(lsst.utils.tests.TestCase):
40 """Base class shared by all tests of the butler and mapper.
42 This class can not inherit from `~lsst.obs.base.tests.ObsTests` since
43 that will trigger tests in this class directly that will fail.
45 This class defines a butler and a mapper for each test subclass.
46 They are stored in the ``_mapper`` and ``_butler`` class attributes
47 to distinguish them from the ``mapper`` and ``butler`` instance
48 attributes used by `~lsst.obs.base.tests.ObsTests`.
49 """
51 instrumentDir = "TBD" # Override in subclass
52 """Name of instrument directory within data/input."""
54 _butler = None
56 @classmethod
57 @abstractmethod
58 def getInstrument(cls):
59 """Retrieve the `lsst.obs.base.Instrument` class for this instrument.
61 Returns
62 -------
63 instrument : `lsst.obs.base.Instrument`
64 The class associated with this instrument.
65 """
66 ...
68 @classmethod
69 def tearDownClass(cls):
70 del cls._butler
72 @classmethod
73 def setUpClass(cls):
74 cls.data_dir = os.path.normpath(os.path.join(DATAROOT, cls.instrumentDir))
75 # Protection against the base class values being used
76 if not os.path.exists(cls.data_dir):
77 raise unittest.SkipTest(f"Data directory {cls.data_dir} does not exist.")
79 instrument = cls.getInstrument()
80 # Assume the test repos use the defaults.
81 collections = [instrument.makeUnboundedCalibrationRunName(),
82 instrument.makeDefaultRawIngestRunName(),
83 instrument.makeCalibrationCollectionName()]
84 cls._butler = lsst.daf.butler.Butler(cls.data_dir, collections=collections,
85 instrument=instrument.getName())
88class ObsLsstObsBaseOverrides(lsst.obs.base.tests.ObsTests):
89 """Specialist butler tests for obs_lsst."""
91 def testRawVisitInfo(self):
92 visitInfo = self.butler.get("raw.visitInfo", self.dataIds["raw"])
93 self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo)
94 # We should always get a valid date and exposure time
95 self.assertIsInstance(visitInfo.getDate(), lsst.daf.base.DateTime)
96 self.assertTrue(visitInfo.getDate().isValid())
97 self.assertEqual(visitInfo.getExposureTime(), self.butler_get_data.exptimes["raw"])
99 def testRawFilename(self):
100 uri = self.butler.getURI("raw", dataId=self.dataIds["raw"])
101 self.assertEqual(uri.basename(), self.raw_filename)