Coverage for tests/test_ddl.py: 30%
31 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-03 09:15 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-03 09:15 +0000
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/>.
22"""Unit tests for methods in butler.ddl module.
23"""
25import unittest
27from astropy.time import Time
28from lsst.daf.butler import ddl, time_utils
31class AstropyTimeNsecTaiTestCase(unittest.TestCase):
32 """A test case for AstropyTimeNsecTai class"""
34 def setUp(self):
35 self.decor = ddl.AstropyTimeNsecTai()
36 # We do not do dialect-specific things
37 self.dialect = None
39 def test_value_none(self):
40 """Tests for converting None (to None)."""
41 value = self.decor.process_bind_param(None, self.dialect)
42 self.assertIsNone(value)
44 value = self.decor.process_result_value(None, self.dialect)
45 self.assertIsNone(value)
47 def test_time_before_epoch(self):
48 """Tests for converting None in bound parameters."""
49 time = Time("1950-01-01T00:00:00", format="isot", scale="tai")
50 value = self.decor.process_bind_param(time, self.dialect)
51 self.assertEqual(value, 0)
53 value = self.decor.process_result_value(value, self.dialect)
54 self.assertEqual(value, time_utils.TimeConverter().epoch)
56 def test_max_time(self):
57 """Tests for converting None in bound parameters."""
58 # there are rounding issues, need more complex comparison
59 time = Time("2101-01-01T00:00:00", format="isot", scale="tai")
60 value = self.decor.process_bind_param(time, self.dialect)
62 value_max = self.decor.process_bind_param(time_utils.TimeConverter().max_time, self.dialect)
63 self.assertEqual(value, value_max)
65 def test_round_trip(self):
66 """Test precision of round-trip conversion."""
67 # do tests at random points between epoch and max. time
68 times = [
69 "1970-01-01T12:00:00.123",
70 "1999-12-31T23:59:59.999999999",
71 "2000-01-01T12:00:00.000000001",
72 "2030-01-01T12:00:00.123456789",
73 "2075-08-17T00:03:45",
74 "2099-12-31T23:00:50",
75 ]
76 for time in times:
77 atime = Time(time, format="isot", scale="tai")
78 value = self.decor.process_bind_param(atime, self.dialect)
79 value = self.decor.process_result_value(value, self.dialect)
80 self.assertTrue(time_utils.TimeConverter().times_equal(atime, value))
83if __name__ == "__main__":
84 unittest.main()