Coverage for tests/test_read_CuratedCalibs.py: 31%

66 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-01 21:12 +0000

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

36 

37 

38def setup_module(module): 

39 lsst.utils.tests.init() 

40 

41 

42class ReadDefectsTestCase(unittest.TestCase): 

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

44 

45 def setUp(self): 

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

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

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

49 

50 def tearDown(self): 

51 del self.cam 

52 del self.defects_path 

53 

54 def test_read_defects(self): 

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

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

57 self.assertEqual(data_type, 'defects') 

58 for s in defects: 

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

60 for d in defects[s]: 

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

62 

63 

64class ReadQeTestCase(unittest.TestCase): 

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

66 

67 def setUp(self): 

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

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

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

71 self.tmp_dir_obj = tempfile.TemporaryDirectory() 

72 

73 def tearDown(self): 

74 del self.cam 

75 del self.qe_path 

76 self.tmp_dir_obj.cleanup() 

77 

78 def read_qe_tester(self, per_amp): 

79 if per_amp: 

80 path_str = 'per_amp' 

81 else: 

82 path_str = 'per_detector' 

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

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

85 'qe_curve', 'ccd00') 

86 os.makedirs(dest_path) 

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

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

89 os.symlink(f, df) 

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

91 self.cam) 

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

93 self.assertEqual(data_type, 'qe_curve') 

94 for s in curves: 

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

96 if per_amp: 

97 for d in curves[s]: 

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

99 

100 def test_read_qe_amp(self): 

101 self.read_qe_tester(True) 

102 

103 def test_read_qe_det(self): 

104 self.read_qe_tester(False) 

105 

106 

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

108 pass 

109 

110 

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

112 lsst.utils.tests.init() 

113 unittest.main()