Coverage for tests/test_ddl.py: 36%

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

33 statements  

1# This file is part of daf_butler. 

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 

22"""Unit tests for methods in butler.ddl module. 

23""" 

24 

25import unittest 

26 

27from astropy.time import Time 

28from lsst.daf.butler import ddl, time_utils 

29 

30 

31class AstropyTimeNsecTaiTestCase(unittest.TestCase): 

32 """A test case for AstropyTimeNsecTai class 

33 """ 

34 

35 def setUp(self): 

36 self.decor = ddl.AstropyTimeNsecTai() 

37 # We do not do dialect-specific things 

38 self.dialect = None 

39 

40 def test_value_none(self): 

41 """Tests for converting None (to None). 

42 """ 

43 value = self.decor.process_bind_param(None, self.dialect) 

44 self.assertIsNone(value) 

45 

46 value = self.decor.process_result_value(None, self.dialect) 

47 self.assertIsNone(value) 

48 

49 def test_time_before_epoch(self): 

50 """Tests for converting None in bound parameters. 

51 """ 

52 time = Time("1950-01-01T00:00:00", format="isot", scale="tai") 

53 value = self.decor.process_bind_param(time, self.dialect) 

54 self.assertEqual(value, 0) 

55 

56 value = self.decor.process_result_value(value, self.dialect) 

57 self.assertEqual(value, time_utils.TimeConverter().epoch) 

58 

59 def test_max_time(self): 

60 """Tests for converting None in bound parameters. 

61 """ 

62 # there are rounding issues, need more complex comparison 

63 time = Time("2101-01-01T00:00:00", format="isot", scale="tai") 

64 value = self.decor.process_bind_param(time, self.dialect) 

65 

66 value_max = self.decor.process_bind_param(time_utils.TimeConverter().max_time, self.dialect) 

67 self.assertEqual(value, value_max) 

68 

69 def test_round_trip(self): 

70 """Test precision of round-trip conversion. 

71 """ 

72 # do tests at random points between epoch and max. time 

73 times = [ 

74 "1970-01-01T12:00:00.123", 

75 "1999-12-31T23:59:59.999999999", 

76 "2000-01-01T12:00:00.000000001", 

77 "2030-01-01T12:00:00.123456789", 

78 "2075-08-17T00:03:45", 

79 "2099-12-31T23:00:50", 

80 ] 

81 for time in times: 

82 atime = Time(time, format="isot", scale="tai") 

83 value = self.decor.process_bind_param(atime, self.dialect) 

84 value = self.decor.process_result_value(value, self.dialect) 

85 self.assertTrue(time_utils.TimeConverter().times_equal(atime, value)) 

86 

87 

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

89 unittest.main()