Coverage for tests/test_identifiers.py: 41%
26 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-16 02:22 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-16 02:22 -0700
1# This file is part of cell_coadds.
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/>.
22import unittest
24from lsst.cell_coadds import CellIdentifiers, ObservationIdentifiers, PatchIdentifiers
25from lsst.cell_coadds.test_utils import generate_data_id
26from lsst.skymap import Index2D
29class IdentifiersTestCase(unittest.TestCase):
30 """Tests for UniformGrid and GridIndex/Index2D's C++/Python
31 translation.
32 """
34 @classmethod
35 def setUpClass(cls) -> None: # noqa: D102
36 cls.data_id = generate_data_id() # type: ignore
38 def test_cell_identifiers(self) -> None:
39 """Test we can construct a CellIdentifiers from a DataCoordinate."""
40 cellIdentifier = CellIdentifiers.from_data_id(
41 self.data_id, cell=Index2D(x=4, y=2) # type: ignore [attr-defined]
42 )
43 self.assertEqual(cellIdentifier.cell, Index2D(x=4, y=2))
44 self.assertEqual(cellIdentifier.tract, 9813)
46 # Test that we cannot create a CellIdentifiers with the signature of a
47 # PatchIdentifiers factory method by accident.
48 with self.assertRaises(TypeError):
49 CellIdentifiers.from_data_id(self.data_id) # type: ignore
51 def test_observation_identifiers(self) -> None:
52 """Test we can construct an ObservationIdentifiers from a
53 DataCoordinate.
54 """
55 observationIdentifier = ObservationIdentifiers.from_data_id(
56 self.data_id # type: ignore [attr-defined]
57 )
58 self.assertEqual(observationIdentifier.visit, 1234)
59 self.assertEqual(observationIdentifier.detector, 9)
61 def test_patch_identifiers(self) -> None:
62 """Test we can construct a PatchIdentifiers from a DataCoordinate."""
63 patchIdentifier = PatchIdentifiers.from_data_id(self.data_id) # type: ignore [attr-defined]
64 self.assertEqual(patchIdentifier.tract, 9813)
65 self.assertEqual(patchIdentifier.patch, Index2D(x=4, y=2))
67 # Test that we cannot create a PatchIdentifiers with the signature of a
68 # CellIdentifiers factory method by accident.
69 with self.assertRaises(TypeError):
70 PatchIdentifiers.from_data_id(self.data_id, cell=Index2D(x=4, y=2)) # type: ignore
73if __name__ == "__main__": 73 ↛ 74line 73 didn't jump to line 74, because the condition on line 73 was never true
74 unittest.main()