Coverage for tests / test_utils.py: 21%

33 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-23 08:46 +0000

1# This file is part of ap_association. 

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 unittest 

23 

24import lsst.daf.butler as dafButler 

25 

26from lsst.ap.association.utils import getMidpointFromTimespan 

27from utils_tests import makeExposure, makeRegionTime 

28 

29 

30class TestUtils(unittest.TestCase): 

31 

32 def test_regionTime_timespan(self): 

33 """Check that the midpoint from a RegionTimeInfo matches the time from 

34 the visitInfo of the exposure. 

35 """ 

36 exposure = makeExposure() 

37 regionTime = makeRegionTime(exposure) 

38 visitTime = exposure.visitInfo.date.toAstropy() 

39 midpoint = getMidpointFromTimespan(regionTime.timespan) 

40 self.assertEqual(visitTime.jd, midpoint.jd) 

41 

42 def test_invalidTimespan(self): 

43 """Test the error handling of getMidpointFromTimespan. 

44 """ 

45 exposure = makeExposure() 

46 visitTime = exposure.visitInfo.date.toAstropy() 

47 timespan_no_end = dafButler.Timespan(begin=visitTime, end=dafButler.Timespan.EMPTY) 

48 timespan_no_begin = dafButler.Timespan(begin=dafButler.Timespan.EMPTY, end=visitTime) 

49 with self.assertRaises(ValueError): 

50 getMidpointFromTimespan(timespan_no_end) 

51 with self.assertRaises(ValueError): 

52 getMidpointFromTimespan(timespan_no_begin) 

53 

54 timespan_none_end = dafButler.Timespan(begin=visitTime, end=None) 

55 timespan_none_begin = dafButler.Timespan(begin=None, end=visitTime) 

56 with self.assertRaises(ValueError): 

57 getMidpointFromTimespan(timespan_none_end, allowUnbounded=False) 

58 with self.assertRaises(ValueError): 

59 getMidpointFromTimespan(timespan_none_begin, allowUnbounded=False) 

60 self.assertEqual(getMidpointFromTimespan(timespan_none_begin).jd, visitTime.jd) 

61 self.assertEqual(getMidpointFromTimespan(timespan_none_end).jd, visitTime.jd) 

62 

63 timespan_none_both = dafButler.Timespan(begin=None, end=None) 

64 with self.assertRaises(ValueError): 

65 getMidpointFromTimespan(timespan_none_both, allowUnbounded=True) 

66 with self.assertRaises(ValueError): 

67 getMidpointFromTimespan(timespan_none_both, allowUnbounded=False)