Coverage for tests/test_diaPipe.py : 33%

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 unittest
23import pandas as pd
25import lsst.afw.image as afwImage
26import lsst.afw.table as afwTable
27import lsst.pipe.base as pipeBase
28import lsst.utils.tests
29from unittest.mock import patch, Mock, DEFAULT
31from lsst.ap.association import DiaPipelineTask
34class TestDiaPipelineTask(unittest.TestCase):
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.doPackageAlerts = doPackageAlerts
42 return config
44 def setUp(self):
45 # schemas are persisted in both Gen 2 and Gen 3 butler as prototypical catalogs
46 srcSchema = afwTable.SourceTable.makeMinimalSchema()
47 srcSchema.addField("base_PixelFlags_flag", type="Flag")
48 srcSchema.addField("base_PixelFlags_flag_offimage", type="Flag")
49 self.srcSchema = afwTable.SourceCatalog(srcSchema)
51 def tearDown(self):
52 pass
54 def testRunWithAlerts(self):
55 """Test running while creating and packaging alerts.
56 """
57 self._testRun(True)
59 def testRunWithoutAlerts(self):
60 """Test running without creating and packaging alerts.
61 """
62 self._testRun(False)
64 def _testRun(self, doPackageAlerts=False):
65 """Test the normal workflow of each ap_pipe step.
66 """
67 config = self._makeDefaultConfig(doPackageAlerts=doPackageAlerts)
68 task = DiaPipelineTask(config=config)
69 # Set DataFrame index testing to always return False. Mocks return
70 # true for this check otherwise.
71 task.testDataFrameIndex = lambda x: False
72 diffIm = Mock(spec=afwImage.ExposureF)
73 exposure = Mock(spec=afwImage.ExposureF)
74 template = Mock(spec=afwImage.ExposureF)
75 diaSrc = Mock(sepc=pd.DataFrame)
76 ccdExposureIdBits = 32
78 # Each of these subtasks should be called once during diaPipe
79 # execution. We use mocks here to check they are being executed
80 # appropriately.
81 subtasksToMock = [
82 "diaCatalogLoader",
83 "associator",
84 "diaCalculation",
85 "diaForcedSource",
86 ]
87 if doPackageAlerts:
88 subtasksToMock.append("alertPackager")
89 else:
90 self.assertFalse(hasattr(task, "alertPackager"))
92 # apdb isn't a subtask, but still needs to be mocked out for correct
93 # execution in the test environment.
94 with patch.multiple(
95 task, **{task: DEFAULT for task in subtasksToMock + ["apdb"]}
96 ):
97 result = task.run(diaSrc,
98 diffIm,
99 exposure,
100 template,
101 ccdExposureIdBits,
102 "g")
103 for subtaskName in subtasksToMock:
104 getattr(task, subtaskName).run.assert_called_once()
105 pipeBase.testUtils.assertValidOutput(task, result)
106 self.assertEqual(result.apdbMarker.db_url, "sqlite://")
107 self.assertEqual(result.apdbMarker.isolation_level,
108 "READ_UNCOMMITTED")
111class MemoryTester(lsst.utils.tests.MemoryTestCase):
112 pass
115def setup_module(module):
116 lsst.utils.tests.init()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 unittest.main()