Hide keyboard shortcuts

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_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/>. 

21 

22"""Test the generateCamera.py script""" 

23 

24import unittest 

25import os 

26import shutil 

27from tempfile import mkdtemp 

28 

29import lsst.utils 

30import lsst.utils.tests 

31 

32from lsst.obs.lsst.script.generateCamera import generateCamera, parseYamlOnPath 

33 

34TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

35POLICYDIR = os.path.normpath(os.path.join(TESTDIR, os.path.pardir, 'policy')) 

36 

37 

38class PhosimToRaftsTestCase(lsst.utils.tests.ExecutablesTestCase): 

39 """Test the phosimToRafts.py utility script.""" 

40 

41 def setUp(self): 

42 self.testdir = mkdtemp(dir=TESTDIR) 

43 

44 def tearDown(self): 

45 shutil.rmtree(self.testdir, ignore_errors=True) 

46 

47 def runGenerateCamera(self, searchPath): 

48 """Run generateCamera with the provided path. 

49 

50 Parameters 

51 ---------- 

52 searchPath : `list` 

53 Directories to search relative to the policy directory. 

54 

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)) 

66 

67 content = parseYamlOnPath(cameraYamlFile, [self.testdir]) 

68 

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) 

73 

74 return content 

75 

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"], 10.112) 

81 

82 def testGenerateCameraTs8(self): 

83 """Test with LATISS in a test directory.""" 

84 content = self.runGenerateCamera(["ts8", "lsstCam", os.path.curdir]) 

85 self.assertEqual(content["name"], "lsstCam") 

86 self.assertEqual(content["plateScale"], 20.0) 

87 

88 def testFailures(self): 

89 with self.assertRaises(RuntimeError): 

90 # Test that we must include a file extension 

91 generateCamera("test", ".") 

92 

93 with self.assertRaises(FileNotFoundError): 

94 # Test that files will be missing if we do not include a full path 

95 generateCamera("test.yaml", "latiss:lsstCam:.") 

96 

97 

98if __name__ == "__main__": 98 ↛ 99line 98 didn't jump to line 99, because the condition on line 98 was never true

99 lsst.utils.tests.init() 

100 unittest.main()