Coverage for tests / test_identifiers.py: 41%

37 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-17 09:22 +0000

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/>. 

21 

22import unittest 

23 

24import lsst.utils.tests 

25from lsst.cell_coadds import CellIdentifiers, ObservationIdentifiers, PatchIdentifiers 

26from lsst.cell_coadds.test_utils import generate_data_id 

27from lsst.skymap import Index2D 

28 

29 

30class IdentifiersTestCase(unittest.TestCase): 

31 """Tests for UniformGrid and GridIndex/Index2D's C++/Python 

32 translation. 

33 """ 

34 

35 @classmethod 

36 def setUpClass(cls) -> None: # noqa: D102 

37 cls.data_id = generate_data_id() # type: ignore 

38 

39 def test_cell_identifiers(self) -> None: 

40 """Test we can construct a CellIdentifiers from a DataCoordinate.""" 

41 cellIdentifier = CellIdentifiers.from_data_id( 

42 self.data_id, 

43 cell=Index2D(x=4, y=2), 

44 ) 

45 self.assertEqual(cellIdentifier.cell, Index2D(x=4, y=2)) 

46 self.assertEqual(cellIdentifier.tract, 9813) 

47 

48 # Test that we cannot create a CellIdentifiers with the signature of a 

49 # PatchIdentifiers factory method by accident. 

50 with self.assertRaises(TypeError): 

51 CellIdentifiers.from_data_id(self.data_id) # type: ignore 

52 

53 def test_observation_identifiers(self) -> None: 

54 """Test we can construct an ObservationIdentifiers from a 

55 DataCoordinate. 

56 """ 

57 observationIdentifier = ObservationIdentifiers.from_data_id( 

58 self.data_id # type: ignore [attr-defined] 

59 ) 

60 self.assertEqual(observationIdentifier.instrument, "DummyCam") 

61 self.assertEqual(observationIdentifier.physical_filter, "r") 

62 self.assertEqual(observationIdentifier.visit, 1234) 

63 self.assertEqual(observationIdentifier.detector, 9) 

64 self.assertEqual(observationIdentifier.day_obs, 20240201) 

65 

66 def test_observation_identifiers_with_backup_detector(self) -> None: 

67 """Test that the optional detector keyword argument does not override 

68 the value present in the data_id. 

69 """ 

70 observationIdentifier = ObservationIdentifiers.from_data_id( 

71 self.data_id, 

72 backup_detector=42, 

73 ) 

74 self.assertEqual(observationIdentifier.detector, 9) 

75 

76 def test_patch_identifiers(self) -> None: 

77 """Test we can construct a PatchIdentifiers from a DataCoordinate.""" 

78 patchIdentifier = PatchIdentifiers.from_data_id(self.data_id) # type: ignore [attr-defined] 

79 self.assertEqual(patchIdentifier.tract, 9813) 

80 self.assertEqual(patchIdentifier.patch, Index2D(x=4, y=2)) 

81 

82 # Test that we cannot create a PatchIdentifiers with the signature of a 

83 # CellIdentifiers factory method by accident. 

84 with self.assertRaises(TypeError): 

85 PatchIdentifiers.from_data_id(self.data_id, cell=Index2D(x=4, y=2)) # type: ignore 

86 

87 

88class TestMemory(lsst.utils.tests.MemoryTestCase): 

89 """Test for memory/resource leaks.""" 

90 

91 

92def setup_module(module): # noqa: D103 

93 lsst.utils.tests.init() 

94 

95 

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

97 lsst.utils.tests.init() 

98 unittest.main()