Coverage for tests / test_rewrite_qe.py: 30%

37 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-05 08:39 +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/>. 

21 

22"""Test the rewrite_ts8_qe_files.py script in bin.src.""" 

23 

24import unittest 

25import os 

26import shutil 

27import tempfile 

28import glob 

29 

30from lsst.obs.lsst.script.rewrite_ts8_qe_files import rewrite_ts8_files 

31from lsst.ip.isr import IntermediateSensorTransmissionCurve 

32from lsst.resources import ResourcePath 

33 

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

35 

36 

37class RewriteQeTestCase(unittest.TestCase): 

38 """Test the rewrite_ts8_qe_files.py utility script.""" 

39 

40 def testRewriteQe(self): 

41 failed = False 

42 root = tempfile.mkdtemp(dir=TESTDIR) 

43 try: 

44 rewrite_ts8_files(os.path.join(TESTDIR, 'data/qe_test/RaftRun10517.p'), 

45 root, '1970-01-01T00:00:00') 

46 files = glob.glob(os.path.join(root, '*', '19700101T000000.ecsv')) 

47 self.assertEqual(len(files), 9) 

48 for f in files: 

49 curve1 = IntermediateSensorTransmissionCurve.readText(f) 

50 

51 rel_path = os.path.relpath(f, root) 

52 with ResourcePath( 

53 f"resource://lsst.obs_lsst_data/resources/ts8/transmission_sensor/{rel_path}", 

54 forceDirectory=False, 

55 ).as_local() as expect_file: 

56 curve2 = IntermediateSensorTransmissionCurve.readText(expect_file.ospath) 

57 

58 # These fields are created every time, and therefore 

59 # differ between the test data and the references. 

60 curve1.getMetadata().pop('DATE') 

61 curve1.getMetadata().pop('CALIB_CREATION_DATE') 

62 curve1.getMetadata().pop('CALIB_CREATION_TIME') 

63 

64 curve2.getMetadata().pop('DATE') 

65 curve2.getMetadata().pop('CALIB_CREATION_DATE') 

66 curve2.getMetadata().pop('CALIB_CREATION_TIME') 

67 

68 self.assertEqual(curve1, curve2) 

69 except Exception: 

70 failed = True 

71 raise 

72 finally: 

73 if failed: 

74 print(f"Output test data located in {root}") 

75 else: 

76 shutil.rmtree(root, ignore_errors=True) 

77 

78 

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

80 unittest.main()