Commit 2dd1f5ca authored by Leo Pound Singer's avatar Leo Pound Singer

Introduce custom exception class

Original: 136222252030abe406e3ec00f907eeb1f6ed043f
parent ccb5c392
......@@ -19,7 +19,11 @@ Modify events by artificially disabling specified detectors.
"""
from .base import *
__all__ = ('DetectorDisabledEventSource',)
__all__ = ('DetectorDisabledEventSource', 'DetectorDisabledError')
class DetectorDisabledError(ValueError):
pass
class DetectorDisabledEventSource(EventSource):
......@@ -51,13 +55,13 @@ class DetectorDisabledEvent(Event):
if self.source.raises:
detectors = {s.detector for s in self.base_event.singles}
if not detectors & disabled_detectors:
raise ValueError(
raise DetectorDisabledError(
'Disabling detectors {{{}}} would have no effect on this '
'event with detectors {{{}}}'.format(
' '.join(disabled_detectors),
' '.join(detectors)))
if not detectors - disabled_detectors:
raise ValueError(
raise DetectorDisabledError(
'Disabling detectors {{{}}} would exclude all data for '
'this event with detectors {{{}}}'.format(
' '.join(disabled_detectors),
......
......@@ -158,7 +158,7 @@ def test_detector_disabled():
for event in nonraising_source.values():
event.singles
for event in raising_source.values():
with raises(ValueError, expected_message):
with raises(events.DetectorDisabledError, expected_message):
event.singles
# Now test that exceptions are raised when they are called for.
......@@ -171,7 +171,7 @@ def test_detector_disabled():
for event in nonraising_source.values():
event.singles
for event in raising_source.values():
with raises(ValueError, expected_message):
with raises(events.DetectorDisabledError, expected_message):
event.singles
def test_hdf(tmpdir):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment