Coverage for tests/test_ticket2352.py: 44%
39 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-09 03:27 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-09 03:27 -0800
1#
2# LSST Data Management System
3# Copyright 2008, 2009, 2010 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#
22# This ticket results from
23# https://dev.lsstcorp.org/trac/ticket/2352
24# "Support multi-extension input FITS files"
26import os
27import os.path
28import unittest
30import lsst.afw.image as afwImage
31from lsst.afw.fits import readMetadata
32import lsst.utils.tests
34from lsst.afw.fits import DEFAULT_HDU
36testPath = os.path.abspath(os.path.dirname(__file__))
37DATA = os.path.join(testPath, "data", "ticket2352.fits")
40class ReadMefTest(unittest.TestCase):
41 """Test the reading of a multi-extension FITS (MEF) file"""
43 def checkExtName(self, name, value, extNum):
44 filename = f"{DATA}[{name}]"
46 header = readMetadata(filename)
47 self.assertEqual(header.getScalar("EXT_NUM"), extNum)
48 self.assertEqual(header.getScalar("EXTNAME").strip(), name)
50 image = afwImage.ImageI(filename, allowUnsafe=True)
51 self.assertEqual(image[0, 0, afwImage.LOCAL], value)
53 def testExtName(self):
54 self.checkExtName("ONE", 1, 2)
55 self.checkExtName("TWO", 2, 3)
56 self.checkExtName("THREE", 3, 4)
58 def checkExtNum(self, hdu, extNum):
59 if hdu is None:
60 hdu = DEFAULT_HDU
61 header = readMetadata(DATA, hdu)
62 self.assertEqual(header.getScalar("EXT_NUM"), extNum)
64 def testExtNum(self):
65 # N.b. The test file was written with 1-indexed EXT_NUMs
66 self.checkExtNum(None, 2) # Should skip PHU
67 self.checkExtNum(0, 1)
68 self.checkExtNum(1, 2)
69 self.checkExtNum(2, 3)
70 self.checkExtNum(3, 4)
73class MemoryTester(lsst.utils.tests.MemoryTestCase):
74 pass
77def setup_module(module):
78 lsst.utils.tests.init()
81if __name__ == "__main__": 81 ↛ 82line 81 didn't jump to line 82, because the condition on line 81 was never true
82 lsst.utils.tests.init()
83 unittest.main()