Coverage for tests/test_read_CuratedCalibs.py: 37%

Shortcuts 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

71 statements  

1# This file is part of pipe_tasks. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import os 

23import glob 

24import unittest 

25import tempfile 

26 

27 

28import lsst.utils.tests 

29from lsst.utils import getPackageDir 

30import lsst.obs.base 

31from lsst.obs.base.test import BaseMapper 

32from lsst.pipe.tasks.read_curated_calibs import read_all 

33import lsst.daf.persistence as dafPersist 

34 

35ROOT = os.path.join(getPackageDir('obs_base'), 'tests') 

36if not os.path.exists(ROOT): 36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true

37 ROOT = None 

38ROOTSkipMsg = "Cannot locate obs_base tests directory, skipping." 

39 

40 

41def setup_module(module): 

42 lsst.utils.tests.init() 

43 

44 

45@unittest.skipIf(ROOT is None, ROOTSkipMsg) 

46class ReadDefectsTestCase(unittest.TestCase): 

47 """A test case for the defect reader.""" 

48 

49 def setUp(self): 

50 butler = dafPersist.ButlerFactory(mapper=BaseMapper(ROOT)).create() 

51 self.cam = butler.get('camera') 

52 self.defects_path = os.path.join(ROOT, 'trivial_camera', 'defects') 

53 

54 def tearDown(self): 

55 del self.cam 

56 del self.defects_path 

57 

58 def test_read_defects(self): 

59 defects, data_type = read_all(self.defects_path, self.cam) 

60 self.assertEqual(len(defects.keys()), 1) # One sensor 

61 self.assertEqual(data_type, 'defects') 

62 for s in defects: 

63 self.assertEqual(len(defects[s].keys()), 2) # Two validity ranges 

64 for d in defects[s]: 

65 self.assertEqual(len(defects[s][d]), 4) # Four defects 

66 

67 

68@unittest.skipIf(ROOT is None, ROOTSkipMsg) 

69class ReadQeTestCase(unittest.TestCase): 

70 """A test case for the qe_curve reader""" 

71 

72 def setUp(self): 

73 butler = dafPersist.ButlerFactory(mapper=BaseMapper(ROOT)).create() 

74 self.cam = butler.get('camera') 

75 self.qe_path = os.path.join(ROOT, 'trivial_camera', 'qe_curve') 

76 self.tmp_dir_obj = tempfile.TemporaryDirectory() 

77 

78 def tearDown(self): 

79 del self.cam 

80 del self.qe_path 

81 self.tmp_dir_obj.cleanup() 

82 

83 def read_qe_tester(self, per_amp): 

84 if per_amp: 

85 path_str = 'per_amp' 

86 else: 

87 path_str = 'per_detector' 

88 files = glob.glob(os.path.join(self.qe_path, 'ccd00', path_str, '*')) 

89 dest_path = os.path.join(self.tmp_dir_obj.name, 'trivial_camera', 

90 'qe_curve', 'ccd00') 

91 os.makedirs(dest_path) 

92 dest_files = [os.path.join(dest_path, os.path.split(f)[1]) for f in files] 

93 for f, df in zip(files, dest_files): 

94 os.symlink(f, df) 

95 curves, data_type = read_all(os.path.join(self.tmp_dir_obj.name, 'trivial_camera', 'qe_curve'), 

96 self.cam) 

97 self.assertEqual(len(curves.keys()), 1) # One sensor 

98 self.assertEqual(data_type, 'qe_curve') 

99 for s in curves: 

100 self.assertEqual(len(curves[s].keys()), 2) # Two validity ranges 

101 if per_amp: 

102 for d in curves[s]: 

103 self.assertEqual(len(curves[s][d].data), 2) # Two amps 

104 

105 def test_read_qe_amp(self): 

106 self.read_qe_tester(True) 

107 

108 def test_read_qe_det(self): 

109 self.read_qe_tester(False) 

110 

111 

112class MemoryTester(lsst.utils.tests.MemoryTestCase): 

113 pass 

114 

115 

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

117 lsst.utils.tests.init() 

118 unittest.main()