Coverage for tests / test_generateCamera.py: 33%
48 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:26 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:26 +0000
1# This file is part of obs_lsst.
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"""Test the generateCamera.py script"""
24import unittest
25import os
26import shutil
27from tempfile import mkdtemp
29from lsst.obs.lsst.script.generateCamera import generateCamera, parseYamlOnPath
31TESTDIR = os.path.abspath(os.path.dirname(__file__))
32POLICYDIR = os.path.normpath(os.path.join(TESTDIR, os.path.pardir, 'policy'))
35class PhosimToRaftsTestCase(unittest.TestCase):
36 """Test the generateCamera.py utility script."""
38 def setUp(self):
39 self.testdir = mkdtemp(dir=TESTDIR)
41 def tearDown(self):
42 shutil.rmtree(self.testdir, ignore_errors=True)
44 def runGenerateCamera(self, searchPath):
45 """Run generateCamera with the provided path.
47 Parameters
48 ----------
49 searchPath : `list`
50 Directories to search relative to the policy directory.
52 Returns
53 -------
54 content : `dict`
55 The content from the generated camera.
56 """
57 camera = "testCamera"
58 cameraYamlFile = f"{camera}.yaml"
59 outfile = os.path.join(self.testdir, cameraYamlFile)
60 searchPath = (os.path.normpath(os.path.join(POLICYDIR, f)) for f in searchPath)
61 generateCamera(outfile, searchPath)
62 self.assertTrue(os.path.exists(outfile))
64 content = parseYamlOnPath(cameraYamlFile, [self.testdir])
66 # Check that some top level keys exist
67 for k in ("CCDs", "AMP_E2V", "AMP_ITL", "CCD_ITL", "CCD_E2V", "RAFT_ITL", "RAFT_E2V",
68 "transforms"):
69 self.assertIn(k, content)
71 return content
73 def testGenerateCameraLatiss(self):
74 """Test with LATISS in a test directory."""
75 content = self.runGenerateCamera(["latiss", "lsstCam", os.path.curdir])
76 self.assertEqual(content["name"], "LATISS")
77 self.assertEqual(content["plateScale"], 9.5695)
79 def testGenerateCameraTs8(self):
80 """Test with ts8 in a test directory."""
81 content = self.runGenerateCamera(["ts8", "lsstCam", os.path.curdir])
82 self.assertEqual(content["name"], "LSST-TS8")
83 self.assertEqual(content["plateScale"], 20.005867576692737)
85 def testGenerateCamera(self):
86 """Test with lsstCam in a test directory."""
87 content = self.runGenerateCamera(["lsstCam", os.path.curdir])
88 # Test that the raft name mapping is working
89 self.assertTrue('R00_SW0' in content['CCDs'])
90 self.assertTrue('R40_SW0' in content['CCDs'])
91 self.assertTrue('R04_SW0' in content['CCDs'])
92 self.assertTrue('R44_SW0' in content['CCDs'])
93 # Also make sure no bad names are sneaking through
94 self.assertEqual([x for x in content['CCDs'] if 'W_' in x], [])
95 self.assertEqual(content["name"], "LSSTCam")
96 self.assertEqual(content["plateScale"], 20.005867576692737)
97 # SW0 is extrafocal is negative-z in DVCS
98 self.assertEqual(content["CCDs"]["R04_SW0"]["offset"][2], -1.5)
100 def testFailures(self):
101 with self.assertRaises(RuntimeError):
102 # Test that we must include a file extension
103 generateCamera("test", ".")
105 with self.assertRaises(FileNotFoundError):
106 # Test that files will be missing if we do not include a full path
107 generateCamera("test.yaml", "latiss:lsstCam:.")
110if __name__ == "__main__": 110 ↛ 111line 110 didn't jump to line 111 because the condition on line 110 was never true
111 unittest.main()