diff --git a/src/aarecommon/config/beamline.py b/src/aarecommon/config/beamline.py index 9f18142..8ca01e8 100644 --- a/src/aarecommon/config/beamline.py +++ b/src/aarecommon/config/beamline.py @@ -29,9 +29,13 @@ class BeamlineYAMLConfig: def mx_beamline() -> MXBeamline: name = os.getenv("BEAMLINE") if name is None: - return MXBeamline.SIMULATED + raise ValueError("Please set the BEAMLINE environment variable to run AareDAQ") name = name.strip().upper() - return MXBeamline[name] if name in MXBeamline.__members__ else MXBeamline.SIMULATED + if name in MXBeamline.__members__: + return MXBeamline[name] + raise ValueError( + f"{name} is not a valid value for BEAMLINE. Please set one of {MXBeamline.__members__}" + ) def get_jfjoch_url(bl: MXBeamline) -> str: diff --git a/tests/test_beamline.py b/tests/test_beamline.py index acc8ea5..dadcb9c 100644 --- a/tests/test_beamline.py +++ b/tests/test_beamline.py @@ -1,14 +1,18 @@ import os from unittest.mock import patch -from aarecommon.models.beamline import MXBeamline +import pytest + from aarecommon.config.beamline import mx_beamline +from aarecommon.models.beamline import MXBeamline def test_mx_beamline_default(): with patch.dict(os.environ, {}, clear=True): - # If BEAMLINE is not set, it should return SIMULATED - assert mx_beamline() == MXBeamline.SIMULATED + with pytest.raises(ValueError) as e: + # If BEAMLINE is not set, it should raise + mx_beamline() + assert e.match("set the BEAMLINE") def test_mx_beamline_x10sa(): @@ -22,5 +26,7 @@ def test_mx_beamline_x06sa(): def test_mx_beamline_invalid(): - with patch.dict(os.environ, {"BEAMLINE": "INVALID"}): - assert mx_beamline() == MXBeamline.SIMULATED + with pytest.raises(ValueError) as e: + with patch.dict(os.environ, {"BEAMLINE": "INVALID"}): + mx_beamline() + assert e.match("not a valid value")