Skip to content

Commit

Permalink
Add tests of runQuantum exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Feb 8, 2024
1 parent b385dab commit a17eaf8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/test_calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,54 @@ def test_lintConnections(self):
Connections = CalibrateImageTask.ConfigClass.ConnectionsClass
lsst.pipe.base.testUtils.lintConnections(Connections)

def test_runQuantum_exception(self):
"""Test handling of exceptions handling in runQuantum.
"""
task = CalibrateImageTask()
lsst.pipe.base.testUtils.assertValidInitOutput(task)

quantum = lsst.pipe.base.testUtils.makeQuantum(
task, self.butler, self.visit_id,
{"exposures": [self.exposure0_id],
"astrometry_ref_cat": [self.htm_id],
"photometry_ref_cat": [self.htm_id],
# outputs
"exposure": self.visit_id,
"stars": self.visit_id,
"background": self.visit_id,
"psf_stars": self.visit_id,
"applied_photo_calib": self.visit_id,
"initial_pvi_background": self.visit_id,
"astrometry_matches": self.visit_id,
"photometry_matches": self.visit_id,
})

# A generic exception should raise directly.
msg = "mocked run exception"
with (
mock.patch.object(task, "run", side_effect=ValueError(msg)),
self.assertRaisesRegex(ValueError, "mocked run exception")
):
lsst.pipe.base.testUtils.runTestQuantum(task, self.butler, quantum, mockRun=False)

class TestError(lsst.pipe.base.RepeatableQuantumError):
@property
def metadata(self):
return {"something": 12345}

msg = "mocked run exception"
with (
mock.patch.object(task, "run", side_effect=TestError(msg)),
self.assertRaisesRegex(ValueError, "mocked run exception"),
lsst.log.UsePythonLogging(), # so that assertLogs works with lsst.log
):
with self.assertLogs("lsst.calibrateImage", level="WARNING") as cm:
lsst.pipe.base.testUtils.runTestQuantum(task,
self.butler,
quantum,
mockRun=False)
self.assertIn(msg, "\n".join(cm.output))
self.assertIn("writing available datasets", "\n".join(cm.output))

def setup_module(module):
lsst.utils.tests.init()
Expand Down

0 comments on commit a17eaf8

Please sign in to comment.