Coverage for tests/test_filters.py: 44%

39 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-27 09:12 +0000

1# This file is part of obs_base. 

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.afw.image 

25import lsst.pex.exceptions 

26import lsst.utils.tests 

27from lsst.obs.base import FilterDefinition, FilterDefinitionCollection 

28 

29 

30class TestFilterDefinitionCollection(lsst.utils.tests.TestCase): 

31 """Test filter definition collection.""" 

32 

33 def setUp(self): 

34 self.filters1 = FilterDefinitionCollection( 

35 FilterDefinition(physical_filter="abc"), 

36 FilterDefinition(physical_filter="def", band="d", doc="This is a test filter."), 

37 ) 

38 self.filters2 = FilterDefinitionCollection( 

39 FilterDefinition(physical_filter="abc"), 

40 FilterDefinition(physical_filter="def", band="dd"), 

41 ) 

42 

43 def test_findAll(self): 

44 self.assertEqual(set(self.filters1.findAll("r")), set()) 

45 matches = self.filters1.findAll("abc") 

46 self.assertEqual(len(matches), 1) 

47 match = list(matches)[0] 

48 self.assertEqual(match.physical_filter, "abc") 

49 

50 def test_physical_to_band(self): 

51 """Test that the physical_to_band dict returns expected values.""" 

52 self.assertIsNone(self.filters1.physical_to_band["abc"]) 

53 self.assertEqual(self.filters1.physical_to_band["def"], "d") 

54 self.assertIsNone(self.filters2.physical_to_band["abc"]) 

55 self.assertEqual(self.filters2.physical_to_band["def"], "dd") 

56 

57 

58class TestFilterDefinition(lsst.utils.tests.TestCase): 

59 """Test filter definition.""" 

60 

61 def setUp(self): 

62 self.filter_g = FilterDefinition(band="g", physical_filter="HSC-G", alias={"ABCDEFG"}) 

63 self.filter_g2 = FilterDefinition(band="g", physical_filter="HSC-G2", afw_name="g2", alias={"HIJK"}) 

64 

65 self.physical_only = FilterDefinition(physical_filter="physical") 

66 self.afw_name = FilterDefinition(physical_filter="afw_name", afw_name="afw only") 

67 self.abstract = FilterDefinition(physical_filter="abstract", band="abstract only") 

68 

69 def test_physical_only(self): 

70 """physical_filter is the only name this filter has.""" 

71 self.assertEqual( 

72 self.physical_only.makeFilterLabel(), lsst.afw.image.FilterLabel(physical="physical") 

73 ) 

74 

75 def test_afw_name(self): 

76 """afw_name is the Filter name, physical_filter is an alias.""" 

77 self.assertEqual(self.afw_name.makeFilterLabel(), lsst.afw.image.FilterLabel(physical="afw_name")) 

78 

79 def test_abstract_only(self): 

80 """Band is the Filter name, physical_filter is an alias.""" 

81 self.assertEqual( 

82 self.abstract.makeFilterLabel(), 

83 lsst.afw.image.FilterLabel(band="abstract only", physical="abstract"), 

84 ) 

85 

86 

87class MemoryTester(lsst.utils.tests.MemoryTestCase): 

88 """Check for file leaks.""" 

89 

90 

91def setup_module(module): 

92 """Initialize pytest.""" 

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()