Coverage for tests/test_diaPipe.py : 35%

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/>.
22import os
23import unittest
25import lsst.afw.image as afwImage
26import lsst.afw.table as afwTable
27import lsst.pipe.base as pipeBase
28from lsst.utils import getPackageDir
29import lsst.utils.tests
30from unittest.mock import patch, Mock, DEFAULT
32from lsst.ap.association import DiaPipelineTask
35class TestDiaPipelineTask(unittest.TestCase):
37 @classmethod
38 def _makeDefaultConfig(cls, doPackageAlerts=False):
39 config = DiaPipelineTask.ConfigClass()
40 config.apdb.db_url = "sqlite://"
41 config.apdb.isolation_level = "READ_UNCOMMITTED"
42 config.diaSourceDpddifier.copyColumns = {"id": "id",
43 "parent": "parent",
44 "coord_ra": "coord_ra",
45 "coord_dec": "coord_dec"}
46 config.diaSourceDpddifier.flagMap = os.path.join(
47 getPackageDir("ap_association"),
48 "tests",
49 "test-flag-map.yaml")
50 config.doPackageAlerts = doPackageAlerts
51 return config
53 def setUp(self):
54 # schemas are persisted in both Gen 2 and Gen 3 butler as prototypical catalogs
55 srcSchema = afwTable.SourceTable.makeMinimalSchema()
56 srcSchema.addField("base_PixelFlags_flag", type="Flag")
57 srcSchema.addField("base_PixelFlags_flag_offimage", type="Flag")
58 self.srcSchema = afwTable.SourceCatalog(srcSchema)
60 def tearDown(self):
61 pass
63 def testRunQuantum(self):
64 pass
66 def testRunWithAlerts(self):
67 """Test running while creating and packaging alerts.
68 """
69 self._testRun(True)
71 def testRunWithoutAlerts(self):
72 """Test running without creating and packaging alerts.
73 """
74 self._testRun(False)
76 def _testRun(self, doPackageAlerts=False):
77 """Test the normal workflow of each ap_pipe step.
78 """
79 config = self._makeDefaultConfig(doPackageAlerts=doPackageAlerts)
80 task = DiaPipelineTask(
81 config=config,
82 initInputs={"diaSourceSchema": self.srcSchema})
83 diffIm = Mock(spec=afwImage.ExposureF)
84 exposure = Mock(spec=afwImage.ExposureF)
85 template = Mock(spec=afwImage.ExposureF)
86 diaSrc = Mock(sepc=afwTable.SourceCatalog)
87 ccdExposureIdBits = 32
89 # Each of these subtasks should be called once during diaPipe
90 # execution. We use mocks here to check they are being executed
91 # appropriately.
92 subtasksToMock = [
93 "diaCatalogLoader",
94 "diaSourceDpddifier",
95 "associator",
96 "diaForcedSource",
97 ]
98 if doPackageAlerts:
99 subtasksToMock.append("alertPackager")
100 else:
101 self.assertFalse(hasattr(task, "alertPackager"))
103 # apdb isn't a subtask, but still needs to be mocked out for correct
104 # execution in the test environment.
105 with patch.multiple(
106 task, **{task: DEFAULT for task in subtasksToMock + ["apdb"]}
107 ):
108 result = task.run(diaSrc,
109 diffIm,
110 exposure,
111 template,
112 ccdExposureIdBits)
113 for subtaskName in subtasksToMock:
114 getattr(task, subtaskName).run.assert_called_once()
115 pipeBase.testUtils.assertValidOutput(task, result)
116 self.assertEqual(result.apdbMarker.db_url, "sqlite://")
117 self.assertEqual(result.apdbMarker.isolation_level,
118 "READ_UNCOMMITTED")
121class MemoryTester(lsst.utils.tests.MemoryTestCase):
122 pass
125def setup_module(module):
126 lsst.utils.tests.init()
129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true
130 lsst.utils.tests.init()
131 unittest.main()