Coverage for tests / test_instrument.py: 46%
24 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-26 09:02 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-26 09:02 +0000
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/>.
22"""Tests of the Instrument class."""
24import datetime
25import unittest
27from lsst.obs.base import Instrument
28from lsst.obs.base.instrument_tests import DummyCam, InstrumentTestData, InstrumentTests
31class InstrumentTestCase(InstrumentTests, unittest.TestCase):
32 """Test for Instrument."""
34 instrument = DummyCam()
36 data = InstrumentTestData(
37 name="DummyCam", nDetectors=2, firstDetectorName="RXX_S00", physical_filters={"dummy_g", "dummy_u"}
38 )
40 def test_getCamera(self):
41 """No camera defined in DummyCam."""
42 return
44 def test_collectionTimestamps(self):
45 self.assertEqual(
46 Instrument.formatCollectionTimestamp("2018-05-03"),
47 "20180503T000000Z",
48 )
49 self.assertEqual(
50 Instrument.formatCollectionTimestamp("2018-05-03T14:32:16"),
51 "20180503T143216Z",
52 )
53 self.assertEqual(
54 Instrument.formatCollectionTimestamp("20180503T143216Z"),
55 "20180503T143216Z",
56 )
57 self.assertEqual(
58 Instrument.formatCollectionTimestamp(datetime.datetime(2018, 5, 3, 14, 32, 16)),
59 "20180503T143216Z",
60 )
61 formattedNow = Instrument.makeCollectionTimestamp()
62 self.assertIsInstance(formattedNow, str)
63 datetimeThen1 = datetime.datetime.strptime(formattedNow, "%Y%m%dT%H%M%S%z")
64 self.assertEqual(datetimeThen1.tzinfo, datetime.UTC)
66 def test_group_name(self):
67 """Test group name to ID conversion."""
68 self.assertEqual(self.instrument.group_name_to_group_id("1:234-5.6"), 123456)
69 with self.assertRaises(ValueError):
70 self.instrument.group_name_to_group_id("no_int")
73if __name__ == "__main__": 73 ↛ 74line 73 didn't jump to line 74 because the condition on line 73 was never true
74 unittest.main()