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