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. ...@@ -19,7 +19,11 @@ Modify events by artificially disabling specified detectors.
""" """
from .base import * from .base import *
__all__ = ('DetectorDisabledEventSource',) __all__ = ('DetectorDisabledEventSource', 'DetectorDisabledError')
class DetectorDisabledError(ValueError):
pass
class DetectorDisabledEventSource(EventSource): class DetectorDisabledEventSource(EventSource):
...@@ -51,13 +55,13 @@ class DetectorDisabledEvent(Event): ...@@ -51,13 +55,13 @@ class DetectorDisabledEvent(Event):
if self.source.raises: if self.source.raises:
detectors = {s.detector for s in self.base_event.singles} detectors = {s.detector for s in self.base_event.singles}
if not detectors & disabled_detectors: if not detectors & disabled_detectors:
raise ValueError( raise DetectorDisabledError(
'Disabling detectors {{{}}} would have no effect on this ' 'Disabling detectors {{{}}} would have no effect on this '
'event with detectors {{{}}}'.format( 'event with detectors {{{}}}'.format(
' '.join(disabled_detectors), ' '.join(disabled_detectors),
' '.join(detectors))) ' '.join(detectors)))
if not detectors - disabled_detectors: if not detectors - disabled_detectors:
raise ValueError( raise DetectorDisabledError(
'Disabling detectors {{{}}} would exclude all data for ' 'Disabling detectors {{{}}} would exclude all data for '
'this event with detectors {{{}}}'.format( 'this event with detectors {{{}}}'.format(
' '.join(disabled_detectors), ' '.join(disabled_detectors),
......
...@@ -158,7 +158,7 @@ def test_detector_disabled(): ...@@ -158,7 +158,7 @@ def test_detector_disabled():
for event in nonraising_source.values(): for event in nonraising_source.values():
event.singles event.singles
for event in raising_source.values(): for event in raising_source.values():
with raises(ValueError, expected_message): with raises(events.DetectorDisabledError, expected_message):
event.singles event.singles
# Now test that exceptions are raised when they are called for. # Now test that exceptions are raised when they are called for.
...@@ -171,7 +171,7 @@ def test_detector_disabled(): ...@@ -171,7 +171,7 @@ def test_detector_disabled():
for event in nonraising_source.values(): for event in nonraising_source.values():
event.singles event.singles
for event in raising_source.values(): for event in raising_source.values():
with raises(ValueError, expected_message): with raises(events.DetectorDisabledError, expected_message):
event.singles event.singles
def test_hdf(tmpdir): 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