Coverage for tests/test_instrument.py : 44%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of obs_base.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://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/>.
22import datetime
23import unittest
25from lsst.obs.base import Instrument, FilterDefinitionCollection
26from lsst.obs.base.gen2to3 import TranslatorFactory
27from lsst.obs.base.instrument_tests import InstrumentTests, InstrumentTestData
28from lsst.daf.butler.core.utils import getFullTypeName
30"""Tests of the Instrument class.
31"""
34class DummyCam(Instrument):
36 filterDefinitions = FilterDefinitionCollection()
38 @classmethod
39 def getName(cls):
40 return "DummyCam"
42 def getCamera(self):
43 return None
45 def register(self, registry):
46 """Insert Instrument, physical_filter, and detector entries into a
47 `Registry`.
48 """
49 dataId = {"instrument": self.getName(), "class_name": getFullTypeName(DummyCam)}
50 with registry.transaction():
51 registry.syncDimensionData("instrument", dataId)
52 for f in ("dummy_g", "dummy_u"):
53 registry.syncDimensionData("physical_filter",
54 dict(dataId, physical_filter=f, band=f[-1]))
55 for d in (1, 2):
56 registry.syncDimensionData("detector",
57 dict(dataId, id=d, full_name=str(d)))
59 def getRawFormatter(self, dataId):
60 # Docstring inherited fromt Instrument.getRawFormatter.
61 return None
63 def writeCuratedCalibrations(self, butler):
64 pass
66 def applyConfigOverrides(self, name, config):
67 pass
69 def makeDataIdTranslatorFactory(self) -> TranslatorFactory:
70 return TranslatorFactory()
73class InstrumentTestCase(InstrumentTests, unittest.TestCase):
74 """Test for Instrument.
75 """
77 instrument = DummyCam()
79 data = InstrumentTestData(name="DummyCam",
80 nDetectors=2,
81 firstDetectorName="1",
82 physical_filters={"dummy_g", "dummy_u"})
84 def test_getCamera(self):
85 """No camera defined in DummyCam"""
86 return
88 def test_collectionTimestamps(self):
89 self.assertEqual(
90 Instrument.formatCollectionTimestamp("2018-05-03"),
91 "20180503T000000Z",
92 )
93 self.assertEqual(
94 Instrument.formatCollectionTimestamp("2018-05-03T14:32:16"),
95 "20180503T143216Z",
96 )
97 self.assertEqual(
98 Instrument.formatCollectionTimestamp("20180503T143216Z"),
99 "20180503T143216Z",
100 )
101 self.assertEqual(
102 Instrument.formatCollectionTimestamp(datetime.datetime(2018, 5, 3, 14, 32, 16)),
103 "20180503T143216Z",
104 )
105 formattedNow = Instrument.makeCollectionTimestamp()
106 self.assertIsInstance(formattedNow, str)
107 datetimeThen1 = datetime.datetime.strptime(formattedNow, "%Y%m%dT%H%M%S%z")
108 self.assertEqual(datetimeThen1.tzinfo, datetime.timezone.utc)
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112, because the condition on line 111 was never true
112 unittest.main()