Coverage for tests / test_calibType.py: 33%
53 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-24 08:28 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-24 08:28 +0000
1# This file is part of ip_isr.
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 <https://www.gnu.org/licenses/>.
21import unittest
22import tempfile
23import logging
25import lsst.utils.tests
27from lsst.ip.isr import IsrProvenance, IsrCalib
30class FakeExposure():
31 def __init__(self, **kwargs):
32 self.metadata = kwargs
34 def getMetadata(self):
35 return self.metadata
38class IsrCalibCases(lsst.utils.tests.TestCase):
39 """Test unified calibration type.
40 """
41 def setUp(self):
42 self.calib = IsrProvenance(detectorName='testCalibType Det00',
43 detectorId=0,
44 instrument="TestInst",
45 calibType="Test Calib")
46 self.calib.updateMetadata()
47 self.calib.fromDataIds([{'exposure': 1234, 'detector': 0, 'filter': 'G'},
48 {'exposure': 1235, 'detector': 0, 'filter': 'G'},
49 {'exposure': 1234, 'detector': 1, 'filter': 'G'},
50 {'exposure': 1235, 'detector': 1, 'filter': 'G'}])
51 self.exposure1 = FakeExposure(SEQNAME='sequencer A', SEQFILE='my.seq', SEQCKSUM='abcdef')
52 self.exposure2 = FakeExposure(SEQNAME='sequencer B', SEQFILE='my.seq')
54 def runText(self, textType):
55 filename = tempfile.mktemp()
56 usedFilename = self.calib.writeText(filename + textType)
57 fromText = IsrProvenance.readText(usedFilename)
58 self.assertEqual(self.calib, fromText)
60 # Test generic interface:
61 fromGeneric = IsrCalib.readText(usedFilename)
62 self.assertEqual(self.calib, fromGeneric)
64 def test_Text(self):
65 self.runText('.yaml')
66 self.runText('.ecsv')
68 def test_Fits(self):
69 filename = tempfile.mktemp()
70 usedFilename = self.calib.writeFits(filename + '.fits')
71 fromFits = IsrProvenance.readFits(usedFilename)
72 self.assertEqual(self.calib, fromFits)
74 with self.assertLogs(level=logging.WARNING) as cm:
75 fromFits.updateMetadataFromExposures([self.exposure1, self.exposure2, None])
76 self.assertIn("Metadata mismatch!", cm.output[0])
77 fromFits.updateMetadata(setDate=True)
78 self.assertNotEqual(self.calib, fromFits)
80 # Test generic interface:
81 fromGeneric = IsrCalib.readFits(usedFilename)
82 self.assertEqual(self.calib, fromGeneric)
84 self.assertEqual(fromFits.metadata["SEQNAME"], "sequencer A")
85 self.assertEqual(fromFits.metadata["SEQFILE"], "my.seq")
86 self.assertEqual(fromFits.metadata["SEQCKSUM"], "abcdef")
87 self.assertEqual(fromFits.metadata["DET_NAME"], "testCalibType Det00")
88 self.assertEqual(fromFits.metadata["DETECTOR"], 0)
89 self.assertEqual(fromFits.metadata["INSTRUME"], "TestInst")
92class MemoryTester(lsst.utils.tests.MemoryTestCase):
93 pass
96def setup_module(module):
97 lsst.utils.tests.init()
100if __name__ == "__main__": 100 ↛ 101line 100 didn't jump to line 101 because the condition on line 100 was never true
101 import sys
102 setup_module(sys.modules[__name__])
103 unittest.main()