diff --git a/tests/test_calibrateImage.py b/tests/test_calibrateImage.py index 75801934b..5f319ffb4 100644 --- a/tests/test_calibrateImage.py +++ b/tests/test_calibrateImage.py @@ -28,6 +28,7 @@ import numpy as np import lsst.afw.image as afwImage +import lsst.afw.math as afwMath import lsst.afw.table as afwTable import lsst.daf.base import lsst.daf.butler.tests as butlerTests @@ -575,15 +576,23 @@ def test_runQuantum_exception(self): ): lsst.pipe.base.testUtils.runTestQuantum(task, self.butler, quantum, mockRun=False) + # A RepeatableQuantumError should write partial outputs. class TestError(lsst.pipe.base.RepeatableQuantumError): @property def metadata(self): return {"something": 12345} - msg = "mocked run exception" + def mock_run(exposures, result): + """Mock success through compute_psf, but failure after. + """ + result.exposure = afwImage.ExposureF(10, 10) + result.psf_stars = afwTable.SourceCatalog() + result.background = afwMath.BackgroundList() + raise TestError(msg) + with ( - mock.patch.object(task, "run", side_effect=TestError(msg)), - self.assertRaisesRegex(ValueError, "mocked run exception"), + mock.patch.object(task, "run", side_effect=mock_run), + self.assertRaises(lsst.pipe.base.AnnotatedPartialOutputsError), lsst.log.UsePythonLogging(), # so that assertLogs works with lsst.log ): with self.assertLogs("lsst.calibrateImage", level="WARNING") as cm: @@ -592,7 +601,22 @@ def metadata(self): quantum, mockRun=False) self.assertIn(msg, "\n".join(cm.output)) - self.assertIn("writing available datasets", "\n".join(cm.output)) + + # Check that we did get the annotated partial outputs... + pvi = self.butler.get("initial_pvi", self.visit_id) + self.assertEqual(pvi.getMetadata()["failure_message"], msg) + self.assertIn("TestError", pvi.getMetadata()["failure_type"]) + # this one is broken! + # self.assertEqual(pvi.getMetadata()["failure_metadata"], msg) + stars = self.butler.get("initial_psf_stars_footprints", self.visit_id) + self.assertEqual(stars.getMetadata()["failure_message"], msg) + self.assertIn("TestError", stars.getMetadata()["failure_type"]) + # this one is broken! + # self.assertEqual(pvi.getMetadata()["failure_metadata"], msg) + # ... but not the un-produced outputs. + with self.assertRaises(FileNotFoundError): + self.butler.get("initial_stars_footprints_detector", self.visit_id) + def setup_module(module): lsst.utils.tests.init()