Skip to content

Commit

Permalink
Special-case AnnotatedPartialOutputsError in mocking system.
Browse files Browse the repository at this point in the history
We need this to raise with chaining in the mocks, since that's how
it should always be used in production.
  • Loading branch information
TallJimbo committed Aug 23, 2024
1 parent cfa8010 commit 80c412e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions python/lsst/pipe/base/tests/mocks/_pipeline_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar

from astropy.units import Quantity
from lsst.daf.butler import DataCoordinate, DatasetRef, DeferredDatasetHandle, SerializedDatasetType
from lsst.daf.butler import DataCoordinate, DatasetRef, DeferredDatasetHandle, Quantum, SerializedDatasetType
from lsst.pex.config import Config, ConfigDictField, ConfigurableField, Field, ListField
from lsst.utils.doImport import doImportType
from lsst.utils.introspection import get_full_type_name
from lsst.utils.iteration import ensure_iterable

from ... import connectionTypes as cT
from ..._status import AnnotatedPartialOutputsError, RepeatableQuantumError
from ...config import PipelineTaskConfig
from ...connections import InputQuantizedConnection, OutputQuantizedConnection, PipelineTaskConnections
from ...pipeline_graph import PipelineGraph
Expand Down Expand Up @@ -291,18 +292,18 @@ def runQuantum(
# Possibly raise an exception.
if self.data_id_match is not None and self.data_id_match.match(quantum.dataId):
assert self.fail_exception is not None, "Exception type must be defined"
message = f"Simulated failure: task={self.getName()} dataId={quantum.dataId}"

if self.memory_required is not None:
if butlerQC.resources.max_mem < self.memory_required:
_LOG.info(
"Simulating out-of-memory failure for task '%s' on quantum %s",
self.getName(),
quantum.dataId,
)
raise self.fail_exception(message)
self._fail(quantum)

Check warning on line 303 in python/lsst/pipe/base/tests/mocks/_pipeline_task.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/tests/mocks/_pipeline_task.py#L303

Added line #L303 was not covered by tests
else:
_LOG.info("Simulating failure of task '%s' on quantum %s", self.getName(), quantum.dataId)
raise self.fail_exception(message)
self._fail(quantum)

Check warning on line 306 in python/lsst/pipe/base/tests/mocks/_pipeline_task.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/tests/mocks/_pipeline_task.py#L306

Added line #L306 was not covered by tests

# Populate the bit of provenance we store in all outputs.
_LOG.info("Reading input data for task '%s' on quantum %s", self.getName(), quantum.dataId)
Expand Down Expand Up @@ -351,6 +352,25 @@ def runQuantum(

_LOG.info("Finished mocking task '%s' on quantum %s", self.getName(), quantum.dataId)

def _fail(self, quantum: Quantum) -> None:
"""Raise the configured exception.
Parameters
----------
quantum : `lsst.daf.butler.Quantum`
Quantum producing the error.
"""
message = f"Simulated failure: task={self.getName()} dataId={quantum.dataId}"

Check warning on line 363 in python/lsst/pipe/base/tests/mocks/_pipeline_task.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/tests/mocks/_pipeline_task.py#L363

Added line #L363 was not covered by tests
if self.fail_exception is AnnotatedPartialOutputsError:
# This exception is expected to always chain another.
try:
raise RepeatableQuantumError(message)
except RepeatableQuantumError as err:
raise AnnotatedPartialOutputsError() from err

Check warning on line 369 in python/lsst/pipe/base/tests/mocks/_pipeline_task.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/tests/mocks/_pipeline_task.py#L366-L369

Added lines #L366 - L369 were not covered by tests
else:
assert self.fail_exception is not None, "Method should not be called."
raise self.fail_exception(message)

Check warning on line 372 in python/lsst/pipe/base/tests/mocks/_pipeline_task.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/tests/mocks/_pipeline_task.py#L371-L372

Added lines #L371 - L372 were not covered by tests


class MockPipelineDefaultTargetConnections(PipelineTaskConnections, dimensions=()):
pass
Expand Down

0 comments on commit 80c412e

Please sign in to comment.