Coverage for tests/test_convert2to3.py : 53%

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_subaru.
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/>.
22"""Unit tests for HSC gen2 to gen3 conversion.
23"""
25import glob
26import os
27import subprocess
28import tempfile
29import unittest
31import lsst.utils.tests
32from lsst.obs.base.gen2to3 import convertTests
33import lsst.obs.subaru
34import lsst.obs.hsc
37testDataPackage = "testdata_subaru"
38try:
39 testDataDirectory = lsst.utils.getPackageDir(testDataPackage)
40except LookupError:
41 testDataDirectory = None
44def createGen2Repo(inputPath):
45 """
46 Construct a gen2 repository for `HscMapper` containing a given set
47 of input data and return its path.
49 Parameters
50 ----------
51 inputPath : `str`
52 Location of data files to ingest.
54 Returns
55 -------
56 path : `str`
57 Path to newly created gen2 repo, with ingested files.
58 """
59 repoPath = tempfile.mkdtemp()
60 with open(os.path.join(repoPath, "_mapper"), "w") as _mapper:
61 print("lsst.obs.hsc.HscMapper", file=_mapper)
62 ingest_cmd = "hscIngestImages.py"
63 files = glob.glob(os.path.join(inputPath, "*.fits.gz"))
64 cmd = [ingest_cmd, repoPath, *files]
65 print(f"Running command: {' '.join(cmd)}")
66 subprocess.run(cmd, check=True)
67 return repoPath
70@unittest.skipIf(testDataDirectory is None, f"{testDataPackage} not setup")
71class ConvertGen2To3TestCase(convertTests.ConvertGen2To3TestCase,
72 lsst.utils.tests.TestCase):
74 instrumentClassName = "lsst.obs.subaru.HyperSuprimeCam"
76 def setUp(self):
77 rawpath = os.path.join(testDataDirectory, 'hsc/raw')
78 self.gen2calib = os.path.join(testDataDirectory, 'hsc/calib')
79 self.gen2root = createGen2Repo(rawpath)
80 self.config = os.path.join(os.path.abspath(os.path.dirname(__file__)),
81 "config", "convert2to3Config.py")
83 self.biases = [{"detector": 50, "calibration_label": "gen2/bias_2013-11-03_050",
84 "instrument": "HSC"}]
85 self.flats = [{"detector": 50, "calibration_label": "gen2/flat_2013-11-03_050_HSC-I",
86 "instrument": "HSC", "physical_filter": "HSC-I"}]
87 self.darks = [{"detector": 50, "calibration_label": "gen2/dark_2013-11-03_050",
88 "instrument": "HSC"}]
89 super().setUp()
90 self.collections.add("calib/HSC")
93def setup_module(module):
94 lsst.utils.tests.init()
97if __name__ == "__main__": 97 ↛ 98line 97 didn't jump to line 98, because the condition on line 97 was never true
98 lsst.utils.tests.init()
99 unittest.main()