Coverage for tests/test_ddl.py: 30%
31 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-11 03:16 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-11 03:16 -0700
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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28"""Unit tests for methods in butler.ddl module.
29"""
31import unittest
33from astropy.time import Time
34from lsst.daf.butler import ddl, time_utils
37class AstropyTimeNsecTaiTestCase(unittest.TestCase):
38 """A test case for AstropyTimeNsecTai class"""
40 def setUp(self):
41 self.decor = ddl.AstropyTimeNsecTai()
42 # We do not do dialect-specific things
43 self.dialect = None
45 def test_value_none(self):
46 """Tests for converting None (to None)."""
47 value = self.decor.process_bind_param(None, self.dialect)
48 self.assertIsNone(value)
50 value = self.decor.process_result_value(None, self.dialect)
51 self.assertIsNone(value)
53 def test_time_before_epoch(self):
54 """Tests for converting None in bound parameters."""
55 time = Time("1950-01-01T00:00:00", format="isot", scale="tai")
56 value = self.decor.process_bind_param(time, self.dialect)
57 self.assertEqual(value, 0)
59 value = self.decor.process_result_value(value, self.dialect)
60 self.assertEqual(value, time_utils.TimeConverter().epoch)
62 def test_max_time(self):
63 """Tests for converting None in bound parameters."""
64 # there are rounding issues, need more complex comparison
65 time = Time("2101-01-01T00:00:00", format="isot", scale="tai")
66 value = self.decor.process_bind_param(time, self.dialect)
68 value_max = self.decor.process_bind_param(time_utils.TimeConverter().max_time, self.dialect)
69 self.assertEqual(value, value_max)
71 def test_round_trip(self):
72 """Test precision of round-trip conversion."""
73 # do tests at random points between epoch and max. time
74 times = [
75 "1970-01-01T12:00:00.123",
76 "1999-12-31T23:59:59.999999999",
77 "2000-01-01T12:00:00.000000001",
78 "2030-01-01T12:00:00.123456789",
79 "2075-08-17T00:03:45",
80 "2099-12-31T23:00:50",
81 ]
82 for time in times:
83 atime = Time(time, format="isot", scale="tai")
84 value = self.decor.process_bind_param(atime, self.dialect)
85 value = self.decor.process_result_value(value, self.dialect)
86 self.assertTrue(time_utils.TimeConverter().times_equal(atime, value))
89if __name__ == "__main__":
90 unittest.main()