|
34 | 34 |
|
35 | 35 |
|
36 | 36 | class GetCalibratedExposureTestCase(lsst.utils.tests.TestCase):
|
| 37 | + """Tests of MakeCoaddTempExpTask.getCalibratedExposure()""" |
37 | 38 | def setUp(self):
|
38 | 39 | np.random.seed(10)
|
39 | 40 |
|
@@ -120,6 +121,63 @@ def test_getCalibratedExposureJointcal(self):
|
120 | 121 | self.assertEqual(result.getWcs(), self.jointcalSkyWcs)
|
121 | 122 |
|
122 | 123 |
|
| 124 | +class MakeCoaddTempExpRunTestCase(lsst.utils.tests.TestCase): |
| 125 | + """Tests of MakeCoaddTempExpTask.run().""" |
| 126 | + def setUp(self): |
| 127 | + self.config = MakeCoaddTempExpConfig() |
| 128 | + self.task = MakeCoaddTempExpTask(self.config) |
| 129 | + dataId = "visit=mock" |
| 130 | + fakeDataRef = unittest.mock.NonCallableMock(lsst.daf.persistence.ButlerDataRef, |
| 131 | + dataId=dataId, |
| 132 | + butlerSubset=unittest.mock.Mock()) |
| 133 | + self.calexpRefList = [fakeDataRef] |
| 134 | + |
| 135 | + bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(100, 100)) |
| 136 | + self.skyInfo = unittest.mock.Mock(bbox=bbox) |
| 137 | + |
| 138 | + self.fakeImage = lsst.afw.image.ExposureF(bbox) |
| 139 | + self.fakeImage.getMaskedImage().set(np.nan, lsst.afw.image.Mask.getPlaneBitMask("NO_DATA"), np.inf) |
| 140 | + |
| 141 | + target = "lsst.pipe.tasks.makeCoaddTempExp.MakeCoaddTempExpTask._prepareEmptyExposure" |
| 142 | + preparePatch = unittest.mock.patch(target, return_value=self.fakeImage) |
| 143 | + preparePatch.start() |
| 144 | + self.addCleanup(preparePatch.stop) |
| 145 | + |
| 146 | + def testGetCalibratedExposureRaisesRuntimeError(self): |
| 147 | + """If getCalibratedExposure() raises anything other than |
| 148 | + MissingExposureError, it should be passed up the chain. |
| 149 | +
|
| 150 | + Previously, all Exceptions were caught, logged at `warn` level, |
| 151 | + and then dropped. |
| 152 | + """ |
| 153 | + mockErr = "Mock Error!" |
| 154 | + target = "lsst.pipe.tasks.makeCoaddTempExp.MakeCoaddTempExpTask.getCalibratedExposure" |
| 155 | + patch = unittest.mock.patch(target, |
| 156 | + new_callable=unittest.mock.Mock, |
| 157 | + side_effect=RuntimeError(mockErr)) |
| 158 | + patch.start() |
| 159 | + self.addCleanup(patch.stop) |
| 160 | + with self.assertRaises(RuntimeError) as cm: |
| 161 | + self.task.run(self.calexpRefList, self.skyInfo) |
| 162 | + self.assertIn(mockErr, str(cm.exception)) |
| 163 | + |
| 164 | + def testGetCalibratedExposureRaisesMissingExposureError(self): |
| 165 | + """If getCalibratedExposure() raises MissingExposureError, |
| 166 | + processing should continue uninterrupted. |
| 167 | + In this case, that means no data is returned, because there is only |
| 168 | + one dataRef available (`self.fakeImage`). |
| 169 | + """ |
| 170 | + mockErr = "No data files exist." |
| 171 | + target = "lsst.pipe.tasks.makeCoaddTempExp.MakeCoaddTempExpTask.getCalibratedExposure" |
| 172 | + patch = unittest.mock.patch(target, |
| 173 | + new_callable=unittest.mock.Mock, |
| 174 | + side_effect=MissingExposureError(mockErr)) |
| 175 | + patch.start() |
| 176 | + self.addCleanup(patch.stop) |
| 177 | + result = self.task.run(self.calexpRefList, self.skyInfo) |
| 178 | + self.assertEqual(result.exposures, {"direct": None}) |
| 179 | + |
| 180 | + |
123 | 181 | def setup_module(module):
|
124 | 182 | lsst.utils.tests.init()
|
125 | 183 |
|
|
0 commit comments