Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Feb 9, 2024
1 parent 148d99b commit afa0039
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/test_calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit afa0039

Please sign in to comment.