Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of ap_association. 

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 os 

23import unittest 

24 

25import lsst.afw.image as afwImage 

26import lsst.afw.table as afwTable 

27from lsst.utils import getPackageDir 

28import lsst.utils.tests 

29from unittest.mock import patch, Mock, DEFAULT 

30 

31from lsst.ap.association import DiaPipelineTask 

32 

33 

34class TestDiaPipelineTask(unittest.TestCase): 

35 

36 @classmethod 

37 def _makeDefaultConfig(cls, doPackageAlerts=False): 

38 config = DiaPipelineTask.ConfigClass() 

39 config.apdb.db_url = "sqlite://" 

40 config.apdb.isolation_level = "READ_UNCOMMITTED" 

41 config.diaSourceDpddifier.copyColumns = {"id": "id", 

42 "parent": "parent", 

43 "coord_ra": "coord_ra", 

44 "coord_dec": "coord_dec"} 

45 config.diaSourceDpddifier.flagMap = os.path.join( 

46 getPackageDir("ap_association"), 

47 "tests", 

48 "test-flag-map.yaml") 

49 config.doPackageAlerts = doPackageAlerts 

50 return config 

51 

52 def setUp(self): 

53 self.srcSchema = afwTable.SourceTable.makeMinimalSchema() 

54 self.srcSchema.addField("base_PixelFlags_flag", type="Flag") 

55 self.srcSchema.addField("base_PixelFlags_flag_offimage", type="Flag") 

56 

57 def tearDown(self): 

58 pass 

59 

60 def testRunQuantum(self): 

61 pass 

62 

63 def testRunWithAlerts(self): 

64 """Test running while creating and packaging alerts. 

65 """ 

66 self._testRun(True) 

67 

68 def testRunWithoutAlerts(self): 

69 """Test running without creating and packaging alerts. 

70 """ 

71 self._testRun(False) 

72 

73 def _testRun(self, doPackageAlerts=False): 

74 """Test the normal workflow of each ap_pipe step. 

75 """ 

76 config = self._makeDefaultConfig(doPackageAlerts=doPackageAlerts) 

77 task = DiaPipelineTask( 

78 config=config, 

79 initInputs={"diaSourceSchema": self.srcSchema}) 

80 diffIm = Mock(spec=afwImage.ExposureF) 

81 exposure = Mock(spec=afwImage.ExposureF) 

82 diaSrc = Mock(sepc=afwTable.SourceCatalog) 

83 ccdExposureIdBits = 32 

84 

85 # Each of these subtasks should be called once during diaPipe 

86 # execution. We use mocks here to check they are being executed 

87 # appropriately. 

88 subtasksToMock = [ 

89 "diaCatalogLoader", 

90 "diaSourceDpddifier", 

91 "associator", 

92 "diaForcedSource", 

93 ] 

94 if doPackageAlerts: 

95 subtasksToMock.append("alertPackager") 

96 else: 

97 self.assertFalse(hasattr(task, "alertPackager")) 

98 

99 # apdb isn't a subtask, but still needs to be mocked out for correct 

100 # execution in the test environment. 

101 with patch.multiple( 

102 task, **{task: DEFAULT for task in subtasksToMock + ["apdb"]} 

103 ): 

104 result = task.run(diaSrc, diffIm, exposure, ccdExposureIdBits) 

105 for subtaskName in subtasksToMock: 

106 getattr(task, subtaskName).run.assert_called_once() 

107 self.assertEqual(result.apdb_marker.db_url, "sqlite://") 

108 self.assertEqual(result.apdb_marker.isolation_level, 

109 "READ_UNCOMMITTED") 

110 

111 

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

113 pass 

114 

115 

116def setup_module(module): 

117 lsst.utils.tests.init() 

118 

119 

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

121 lsst.utils.tests.init() 

122 unittest.main()