Coverage for tests/test_identifiers.py: 38%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-23 02:17 -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/>. 

21 

22import unittest 

23 

24from lsst.cell_coadds import CellIdentifiers, ObservationIdentifiers, PatchIdentifiers 

25from lsst.cell_coadds.test_utils import generate_data_id 

26from lsst.skymap import Index2D 

27 

28 

29class IdentifiersTestCase(unittest.TestCase): 

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

31 translation. 

32 """ 

33 

34 @classmethod 

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

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

37 

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) 

45 

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 

50 

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.instrument, "DummyCam") 

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

60 self.assertEqual(observationIdentifier.visit, 1234) 

61 self.assertEqual(observationIdentifier.detector, 9) 

62 self.assertEqual(observationIdentifier.day_obs, 20240201) 

63 

64 def test_observation_identifiers_with_backup_detector(self) -> None: 

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

66 the value present in the data_id. 

67 """ 

68 observationIdentifier = ObservationIdentifiers.from_data_id( 

69 self.data_id, 

70 backup_detector=42, 

71 ) 

72 self.assertEqual(observationIdentifier.detector, 9) 

73 

74 def test_patch_identifiers(self) -> None: 

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

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

77 self.assertEqual(patchIdentifier.tract, 9813) 

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

79 

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

81 # CellIdentifiers factory method by accident. 

82 with self.assertRaises(TypeError): 

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

84 

85 

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

87 unittest.main()